From b42a81656dc669e4584cf921af2a93eec0fd017c Mon Sep 17 00:00:00 2001 From: Gudmundur Haraldsson Date: Tue, 1 Feb 2022 15:59:57 +0000 Subject: [PATCH] Adding test for vipgoci_run_scan_skip_execution() --- tests/unit/RunScanSkipExecutionTest.php | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/unit/RunScanSkipExecutionTest.php diff --git a/tests/unit/RunScanSkipExecutionTest.php b/tests/unit/RunScanSkipExecutionTest.php new file mode 100644 index 000000000..f785a52a7 --- /dev/null +++ b/tests/unit/RunScanSkipExecutionTest.php @@ -0,0 +1,97 @@ +options = array(); + } + + protected function tearDown(): void { + /* + * We are no longer running the test, + * remove the indication. + */ + vipgoci_unittests_remove_indication_for_test_id( 'RunScanSkipExecutionTest' ); + + unset( $this->options ); + } + + /** + * Check if vipgoci_run_scan_skip_execution() attempts to + * exit. + * + * @covers ::vipgoci_run_scan_skip_execution + */ + public function testRunScanSkipExecution() { + $this->options['skip-execution'] = true; + + ob_start(); + + vipgoci_run_scan_skip_execution( + $this->options + ); + + $printed_data = ob_get_contents(); + + ob_end_clean(); + + /* + * Check if expected string was printed + */ + $printed_data_found = strpos( + $printed_data, + 'Skipping scanning entirely, as determined by configuration;' + ); + + $this->assertTrue( + $printed_data_found !== false + ); + } + + /** + * Check if vipgoci_run_scan_skip_execution() returns + * with exit-status. + * + * @covers ::vipgoci_run_scan_skip_execution + */ + public function testRunScanDoesNotSkipExecution() { + $this->options['skip-execution'] = false; + + ob_start(); + + vipgoci_run_scan_skip_execution( + $this->options + ); + + $printed_data = ob_get_contents(); + + ob_end_clean(); + + /* + * Check if nothing was printed. + */ + $this->assertEmpty( + $printed_data + ); + } +}