-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6: Release 2.0.1
* pr-6: Fix #5: Setting expected values does not work properly Create TestCase that reproduce unwanted behaviour
- Loading branch information
Showing
2 changed files
with
109 additions
and
3 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
106 changes: 106 additions & 0 deletions
106
test/TestUtilsTest/TestCase/TestSetterAndGetterTrait/SpecifyExpectedValueTest.php
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,106 @@ | ||
<?php | ||
|
||
/** | ||
* phpunit-utils | ||
* | ||
* @filesource | ||
* @copyright 2020 CROSS Solution <https://www.cross-solution.de> | ||
* @license MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
namespace Cross\TestUtilsTest\TestCase\TestSetterAndGetterTrait; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Cross\TestUtils\TestCase\TestSetterAndGetterTrait; | ||
|
||
/** | ||
* Testcase for \Cross\TestUtils\TestCase\TestSetterAndGetterTrait | ||
* | ||
* @covers \Cross\TestUtils\TestCase\TestSetterAndGetterTrait | ||
* @author Mathias Gelhausen <[email protected]> | ||
* @group Cross.TestUtils | ||
* @group Cross.TestUtils.TestCase | ||
* @group Cross.TestUtils.TestCase.TestSetterAndGetterTrait | ||
*/ | ||
class SpecifyExpectedValueTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$dummy = new class | ||
{ | ||
public $attr; | ||
public $expect = 'expected'; | ||
|
||
public function setAttr($v) | ||
{ | ||
$this->attr = $v; | ||
return $this->expect; | ||
} | ||
|
||
public function getAttr() | ||
{ | ||
return $this->expect; | ||
} | ||
}; | ||
|
||
$this->target = new class($dummy) | ||
{ | ||
use TestSetterAndGetterTrait; | ||
|
||
public $target; | ||
public $testSetterAndGetter; | ||
public static $result; | ||
|
||
public function __construct($dummy) | ||
{ | ||
$this->target = $dummy; | ||
static::$result = null; | ||
} | ||
|
||
public static function assertEquals($expect) | ||
{ | ||
static::$result = $expect; | ||
} | ||
|
||
public static function assertSame($expect) | ||
{ | ||
static::$result = $expect; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @testWith [true, "a string"] | ||
* [true, [1,2,3]] | ||
* [true, "stdClass", "object"] | ||
* | ||
*/ | ||
public function testSpecifyingExpectedGetterValues($expect, $value, $type = null) | ||
{ | ||
$this->target->target->expect = $expect; | ||
$this->target->testSetterAndGetter( | ||
'attr', | ||
['value' . ($type ? "_$type" : '') => $value, 'expect' => $expect] | ||
); | ||
|
||
static::assertEquals($expect, $this->target::$result); | ||
} | ||
|
||
/** | ||
* @testWith [true] | ||
*/ | ||
public function testSpecifiyingExpectedSetterValues($expect, $type = null) | ||
{ | ||
if ($type === 'object') { | ||
$expect = new $expect(); | ||
} | ||
$this->target->target->expect = $expect; | ||
$this->target->testSetterAndGetter( | ||
'attr', | ||
['getter' => false, 'value' => 'irrelevant', 'setter_value' => $expect] | ||
); | ||
|
||
static::assertEquals($expect, $this->target::$result); | ||
} | ||
} |