| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class TestWP |
| 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\WP as TestedChecker; |
| 13 |
|
| 14 |
/** |
| 15 |
* PHP checker test case. |
| 16 |
*/ |
| 17 |
class TestWP 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( 'wp', $this->checker->get_name() ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @expectedException Exception |
| 37 |
*/ |
| 38 |
public function test_check_should_throw_exception_if_passed_not_numeric_or_string_requirement() { |
| 39 |
$this->checker->check( [ '5.3' ] ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @doesNotPerformAssertions |
| 44 |
*/ |
| 45 |
public function test_check_should_accept_numeric_or_string_requirement() { |
| 46 |
|
| 47 |
$get_bloginfo = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'get_bloginfo' ); |
| 48 |
$get_bloginfo->expects( $this->any() )->willReturn( '5.4' ); |
| 49 |
|
| 50 |
$this->checker->check( '5.3+hotfix' ); |
| 51 |
$this->checker->check( '5.3' ); |
| 52 |
$this->checker->check( 5.3 ); |
| 53 |
$this->checker->check( 5 ); |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
public function test_check_should_pass_when_using_the_same_version() { |
| 58 |
$get_bloginfo = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'get_bloginfo' ); |
| 59 |
$get_bloginfo->expects( $this->once() )->willReturn( '5.3.1' ); |
| 60 |
|
| 61 |
$this->checker->check( '5.3.1' ); |
| 62 |
|
| 63 |
$this->assertEmpty( $this->checker->get_errors() ); |
| 64 |
} |
| 65 |
|
| 66 |
public function test_check_should_not_pass_when_using_lower_version() { |
| 67 |
$get_bloginfo = $this->getFunctionMock( 'Micropackage\Requirements\Checker', 'get_bloginfo' ); |
| 68 |
$get_bloginfo->expects( $this->once() )->willReturn( '5.0.2' ); |
| 69 |
|
| 70 |
$this->checker->check( '5.3' ); |
| 71 |
|
| 72 |
$this->assertNotEmpty( $this->checker->get_errors() ); |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|