This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PHPUnit Good Practices. | ||
* | ||
* (c) Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PHPUnitGoodPractices; | ||
|
||
trait PositiveOverNegativeCountTrait | ||
{ | ||
// TODO: | ||
// public static function assertCount($expectedCount, $haystack, $message = '') | ||
// public static function assertAttributeCount($expectedCount, $haystackAttributeName, $haystackClassOrObject, $message = '') | ||
// public static function assertNotCount($expectedCount, $haystack, $message = '') | ||
// public static function assertAttributeNotCount($expectedCount, $haystackAttributeName, $haystackClassOrObject, $message = '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PHPUnit Good Practices. | ||
* | ||
* (c) Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PHPUnitGoodPractices\Tests; | ||
|
||
use PHPUnit\Framework\Error\Warning; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnitGoodPractices\PositiveOverNegativeCountTrait; | ||
|
||
/** | ||
* @covers \PHPUnitGoodPractices\PositiveOverNegativeCountTrait | ||
*/ | ||
final class PositiveOverNegativeCountTraitTest extends TestCase | ||
{ | ||
use PositiveOverNegativeCountTrait; | ||
|
||
public $fixtureAttributePositive = array(11); | ||
public $fixtureAttributeZero = array(); | ||
|
||
public function expectException($exception) | ||
{ | ||
if (is_callable(array('parent', 'expectException'))) { | ||
parent::expectException($exception); | ||
} else { | ||
$this->setExpectedException($exception); | ||
} | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @param int $expected | ||
* @param bool $shouldCrash | ||
* | ||
* @dataProvider provideAssertCountCases | ||
*/ | ||
public function testAssertCount($data, $expected, $shouldCrash) | ||
{ | ||
if ($shouldCrash) { | ||
$this->expectException(Warning::class); | ||
} | ||
|
||
$this->assertCount($expected, $data); | ||
} | ||
|
||
public function provideAssertCountCases() | ||
{ | ||
return array( | ||
array(array('foo', 'bar'), 2, false), | ||
array(array(), 0, false), | ||
array(array(), -2, true), | ||
); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* @param int $expected | ||
* @param bool $shouldCrash | ||
* | ||
* @dataProvider provideAssertNotCountCases | ||
*/ | ||
public function testAssertNotCount($data, $expected, $shouldCrash) | ||
{ | ||
if ($shouldCrash) { | ||
$this->expectException(Warning::class); | ||
} | ||
|
||
$this->assertNotCount($expected, $data); | ||
} | ||
|
||
public function provideAssertNotCountCases() | ||
{ | ||
return array( | ||
array(array('foo', 'bar'), -2, false), | ||
array(array(), 10, false), | ||
array(array(), -2, true), | ||
); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @param int $expected | ||
* @param bool $shouldCrash | ||
* | ||
* @dataProvider provideAssertAttributeCountCases | ||
*/ | ||
public function testAssertAttributeCount($key, $expected, $shouldCrash) | ||
{ | ||
if ($shouldCrash) { | ||
$this->expectException(Warning::class); | ||
} | ||
|
||
$this->assertAttributeCount($expected, $key, $this); | ||
} | ||
|
||
public function provideAssertAttributeCountCases() | ||
{ | ||
return array( | ||
array('fixtureAttributePositive', count($this->fixtureAttributePositive), false), | ||
array('fixtureAttributeZero', count($this->fixtureAttributeZero), false), | ||
array('fixtureAttributeZero', -1, true), | ||
); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @param int $expected | ||
* @param bool $shouldCrash | ||
* | ||
* @dataProvider provideAssertAttributeCountCases | ||
*/ | ||
public function testAssertAttributeNotCount($key, $expected, $shouldCrash) | ||
{ | ||
if ($shouldCrash) { | ||
$this->expectException(Warning::class); | ||
} | ||
|
||
$this->assertAttributeNotCount($expected, $key, $this); | ||
} | ||
|
||
public function provideAssertAttributeNotCountCases() | ||
{ | ||
return array( | ||
array('fixtureAttributePositive', 10 + count($this->fixtureAttributePositive), false), | ||
array('fixtureAttributeZero', 10 + count($this->fixtureAttributeZero), false), | ||
array('fixtureAttributeZero', -1, true), | ||
); | ||
} | ||
} |