mirror of
https://github.com/Codappix/typo3-php-datasets.git
synced 2024-11-14 08:36:12 +01:00
Daniel Siepmann
5887cb87fe
Allows to import a PHP data set within TYPO3 testing framework. Allows to assert a PHP data set within TYPO3 testing framework.
131 lines
4.1 KiB
PHP
131 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*/
|
|
|
|
namespace Codappix\Typo3PhpDatasets\Tests\Functional;
|
|
|
|
use InvalidArgumentException;
|
|
use PHPUnit\Framework\AssertionFailedError;
|
|
|
|
/**
|
|
* @covers \Codappix\Typo3PhpDatasets\PhpDataSet
|
|
* @covers \Codappix\Typo3PhpDatasets\TestingFramework
|
|
* @testdox The Testing Framework trait
|
|
*/
|
|
class AssertTest extends AbstractFunctionalTestCase
|
|
{
|
|
/**
|
|
* @test
|
|
*/
|
|
public function canAssertAgainstSimpleSet(): void
|
|
{
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php');
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function canAssertAgainstNullValue(): void
|
|
{
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/WithNull.php');
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/WithNull.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function canAssertAgainstDifferentSetOfColumns(): void
|
|
{
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/WithDifferentColumns.php');
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/WithDifferentColumns.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function failsForMissingAssertionWithUid(): void
|
|
{
|
|
$this->expectException(AssertionFailedError::class);
|
|
$this->expectExceptionMessage('Record "pages:1" not found in database');
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertSimpleMissingUidSet.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function failsForDifferingAssertionWithUid(): void
|
|
{
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php');
|
|
|
|
$this->expectException(AssertionFailedError::class);
|
|
$this->expectExceptionMessage(
|
|
'Assertion in data-set failed for "pages:1":'
|
|
. PHP_EOL
|
|
. 'Fields|Assertion |Record '
|
|
. PHP_EOL
|
|
. 'title |Rootpage without match|Rootpage'
|
|
. PHP_EOL
|
|
);
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithUid.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function failsForAssertionWithoutUid(): void
|
|
{
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php');
|
|
|
|
$this->expectException(AssertionFailedError::class);
|
|
$this->expectExceptionMessage(implode(PHP_EOL, [
|
|
'Assertion in data-set failed for "pages":',
|
|
'array(',
|
|
' \'pid\' => \'0\', ',
|
|
' \'title\' => \'Rootpage without match\'',
|
|
')',
|
|
]) . PHP_EOL);
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithoutUid.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function failsForAdditionalNoneAssertedRecords(): void
|
|
{
|
|
$this->importPHPDataSet(__DIR__ . '/Fixtures/WithDifferentColumns.php');
|
|
|
|
$this->expectException(AssertionFailedError::class);
|
|
$this->expectExceptionMessage('Not asserted record found for "pages:2".');
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertAdditionalRecords.php');
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function throwsExceptionIfFileDoesNotExist(): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('The requested PHP data-set file "' . __DIR__ . '/Fixtures/DoesNotExist.php' . '" does not exist.');
|
|
$this->assertPHPDataSet(__DIR__ . '/Fixtures/DoesNotExist.php');
|
|
}
|
|
}
|