forked from sebastianbergmann/dbunit
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
11 changed files
with
182 additions
and
32 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
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
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
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
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
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
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
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
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,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of DbUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPUnit\DbUnit\Tests\Constraint; | ||
|
||
use PHPUnit\DbUnit\Constraint\DataSetIsEqual; | ||
use PHPUnit\DbUnit\DataSet\DefaultDataSet; | ||
use PHPUnit\DbUnit\DataSet\DefaultTable; | ||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata; | ||
use PHPUnit\DbUnit\Exception\InvalidArgumentException; | ||
use PHPUnit\Framework\ExpectationFailedException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DataSetIsEqualTest extends TestCase | ||
{ | ||
public function testMatch(): void | ||
{ | ||
$constraint = $this->createConstraint(); | ||
|
||
$dataSet = new DefaultDataSet([ | ||
new DefaultTable( | ||
new DefaultTableMetadata('table1', ['id', 'col1'], ['id']), | ||
), | ||
new DefaultTable( | ||
new DefaultTableMetadata('table2', ['id', 'col2'], ['id']), | ||
), | ||
]); | ||
|
||
self::assertTrue($constraint->evaluate($dataSet, '', true)); | ||
self::assertFalse($constraint->evaluate(new DefaultDataSet(), '', true)); | ||
self::assertSame('is equal to expected dataset [table1,table2]', $constraint->toString()); | ||
} | ||
|
||
public function testMatchInvalidType(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Only dataset instance can be matched'); | ||
|
||
$constraint = $this->createConstraint(); | ||
$constraint->evaluate(null); | ||
} | ||
|
||
public function testExpectationFailed(): void | ||
{ | ||
$this->expectException(ExpectationFailedException::class); | ||
$this->expectExceptionMessage('Failed asserting that [] is equal to expected dataset [table1,table2].'); | ||
|
||
self::assertThat(new DefaultDataSet(), $this->createConstraint()); | ||
} | ||
|
||
private function createConstraint(): DataSetIsEqual | ||
{ | ||
$dataSet = new DefaultDataSet([ | ||
new DefaultTable( | ||
new DefaultTableMetadata('table1', ['id', 'col1'], ['id']), | ||
), | ||
new DefaultTable( | ||
new DefaultTableMetadata('table2', ['id', 'col2'], ['id']), | ||
), | ||
]); | ||
|
||
return new DataSetIsEqual($dataSet); | ||
} | ||
} |
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,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of DbUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PHPUnit\DbUnit\Tests\Constraint; | ||
|
||
use PHPUnit\DbUnit\Constraint\TableIsEqual; | ||
use PHPUnit\DbUnit\DataSet\DefaultTable; | ||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata; | ||
use PHPUnit\DbUnit\Exception\InvalidArgumentException; | ||
use PHPUnit\Framework\ExpectationFailedException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TableIsEqualTest extends TestCase | ||
{ | ||
public function testMatch(): void | ||
{ | ||
$constraint = $this->createConstraint(); | ||
|
||
$table1 = new DefaultTable( | ||
new DefaultTableMetadata('table1', ['id', 'col1'], ['id']), | ||
); | ||
$table2 = new DefaultTable( | ||
new DefaultTableMetadata('table2', ['id', 'col2'], ['id']), | ||
); | ||
|
||
self::assertTrue($constraint->evaluate($table1, '', true)); | ||
self::assertFalse($constraint->evaluate($table2, '', true)); | ||
self::assertSame( | ||
sprintf('is equal to expected %s', $table1), | ||
$constraint->toString() | ||
); | ||
} | ||
|
||
public function testMatchInvalidType(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Only table instance can be matched'); | ||
|
||
$constraint = $this->createConstraint(); | ||
$constraint->evaluate(null); | ||
} | ||
|
||
public function testExpectationFailed(): void | ||
{ | ||
$table1 = new DefaultTable( | ||
new DefaultTableMetadata('table1', ['id', 'col1'], ['id']), | ||
); | ||
$table2 = new DefaultTable( | ||
new DefaultTableMetadata('table2', ['id', 'col2'], ['id']), | ||
); | ||
|
||
$this->expectException(ExpectationFailedException::class); | ||
$this->expectExceptionMessage( | ||
sprintf( | ||
'Failed asserting that %s is equal to expected %s.', | ||
$table2, | ||
$table1 | ||
) | ||
); | ||
|
||
self::assertThat($table2, $this->createConstraint()); | ||
} | ||
|
||
private function createConstraint(): TableIsEqual | ||
{ | ||
$table = new DefaultTable( | ||
new DefaultTableMetadata('table1', ['id', 'col1'], ['id']), | ||
); | ||
|
||
return new TableIsEqual($table); | ||
} | ||
} |
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