aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/command/clear_cache_command_test.rs
blob: b18557998fe2c67bfaa32783e22b386263469583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! ref: composer/tests/Composer/Test/Command/ClearCacheCommandTest.php

use crate::test_case::{RunOptions, get_application_tester};
use serial_test::serial;
use shirabe::util::platform::Platform;
use shirabe_php_shim::PhpMixed;

fn tear_down() {
    // --no-cache triggers the env to change so make sure the env is cleaned up after these tests run
    Platform::clear_env("COMPOSER_CACHE_DIR");
}

struct TearDown;

impl Drop for TearDown {
    fn drop(&mut self) {
        tear_down();
    }
}

#[test]
#[serial]
fn test_clear_cache_command_success() {
    let _tear_down = TearDown;

    let mut app_tester = get_application_tester();
    app_tester
        .run(
            vec![(PhpMixed::from("command"), PhpMixed::from("clear-cache"))],
            RunOptions::default(),
        )
        .unwrap();

    assert_eq!(0, app_tester.get_status_code());

    let output = app_tester.get_display();
    assert!(
        output.contains("All caches cleared."),
        "expected output to contain 'All caches cleared.', got: {:?}",
        output,
    );
}

#[test]
#[serial]
fn test_clear_cache_command_with_option_garbage_collection() {
    let _tear_down = TearDown;

    let mut app_tester = get_application_tester();
    app_tester
        .run(
            vec![
                (PhpMixed::from("command"), PhpMixed::from("clear-cache")),
                (PhpMixed::from("--gc"), PhpMixed::Bool(true)),
            ],
            RunOptions::default(),
        )
        .unwrap();

    assert_eq!(0, app_tester.get_status_code());

    let output = app_tester.get_display();
    assert!(
        output.contains("All caches garbage-collected."),
        "expected output to contain 'All caches garbage-collected.', got: {:?}",
        output,
    );
}

#[test]
#[serial]
fn test_clear_cache_command_with_option_no_cache() {
    let _tear_down = TearDown;

    let mut app_tester = get_application_tester();
    app_tester
        .run(
            vec![
                (PhpMixed::from("command"), PhpMixed::from("clear-cache")),
                (PhpMixed::from("--no-cache"), PhpMixed::Bool(true)),
            ],
            RunOptions::default(),
        )
        .unwrap();

    assert_eq!(0, app_tester.get_status_code());

    let output = app_tester.get_display();
    assert!(
        output.contains("Cache is not enabled"),
        "expected output to contain 'Cache is not enabled', got: {:?}",
        output,
    );
}