PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.3.48
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.3.48
1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 All 181 releases
disco / vendor / micropackage / requirements / tests / Checker / test-phpextensions.php

test-phpextensions.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.3.48, at vendor/micropackage/requirements/tests/Checker/test-phpextensions.php

111 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class TestPHPExtensions
4 *
5 * @package micropackage/requirements
6 */
7
8 namespace Micropackage\Requirements\Test\Checker;
9
10 use phpmock\Mock;
11 use Micropackage\Requirements\Requirements;
12 use Micropackage\Requirements\Checker\PHPExtensions as TestedChecker;
13
14 /**
15 * PHP checker test case.
16 */
17 class TestPHPExtensions extends \WP_UnitTestCase {
18
19 use \phpmock\phpunit\PHPMock;
20
21 public function setUp() {
22 parent::setUp();
23 $this->checker = new TestedChecker();
24 }
25
26 public function tearDown() {
27 parent::tearDown();
28 Mock::disableAll();
29 }
30
31 public function test_get_name_should_return_valid_name() {
32 $this->assertSame( 'php_extensions', $this->checker->get_name() );
33 }
34
35 /**
36 * @expectedException Exception
37 */
38 public function test_check_should_throw_exception_if_passed_not_array_requirement() {
39 $this->checker->check( '5.3' );
40 }
41
42 /**
43 * @doesNotPerformAssertions
44 */
45 public function test_check_should_accept_numeric_or_associative_array_requirement() {
46
47 $extension_loaded = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'extension_loaded' );
48 $extension_loaded->expects( $this->any() )->willReturn( true );
49
50 $this->checker->check( [ 'test', 'testing' ] );
51 $this->checker->check( [ 'test' => 'test', 'testing' => 'testing' ] );
52
53 }
54
55 public function test_check_should_pass_if_all_extensions_loaded() {
56
57 $extensions = [ 'extension1', 'extension2' ];
58
59 $extension_loaded = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'extension_loaded' );
60 $extension_loaded->expects( $this->any() )
61 ->withConsecutive( [ 'extension1' ], [ 'extension2' ] )
62 ->willReturnOnConsecutiveCalls( true, true );
63
64 $this->checker->check( $extensions );
65
66 $this->assertEmpty( $this->checker->get_errors() );
67
68 }
69
70 public function test_check_should_fail_if_at_least_one_extension_not_loaded() {
71
72 $extensions = [ 'extension1', 'extension2' ];
73
74 $extension_loaded = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'extension_loaded' );
75 $extension_loaded->expects( $this->exactly( 2 ) )
76 ->withConsecutive( [ 'extension1' ], [ 'extension2' ] )
77 ->willReturnOnConsecutiveCalls( true, false );
78
79 $this->checker->check( $extensions );
80
81 $errors = $this->checker->get_errors();
82
83 $this->assertNotEmpty( $errors );
84 $this->assertCount( 1, $errors );
85 $this->assertContains( 'extension2', $errors[0] );
86 $this->assertNotContains( 'extension1', $errors[0] );
87
88 }
89
90 public function test_check_should_fail_if_all_extensions_not_loaded() {
91
92 $extensions = [ 'extension1', 'extension2' ];
93
94 $extension_loaded = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'extension_loaded' );
95 $extension_loaded->expects( $this->exactly( 2 ) )
96 ->withConsecutive( [ 'extension1' ], [ 'extension2' ] )
97 ->willReturnOnConsecutiveCalls( false, false );
98
99 $this->checker->check( $extensions );
100
101 $errors = $this->checker->get_errors();
102
103 $this->assertNotEmpty( $errors );
104 $this->assertCount( 1, $errors );
105 $this->assertContains( 'extension1', $errors[0] );
106 $this->assertContains( 'extension2', $errors[0] );
107
108 }
109
110 }
111