-
Notifications
You must be signed in to change notification settings - Fork 9
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 #19 from andreaswolf/phpunit-tests
Integrate PhpUnit tests
- Loading branch information
Showing
16 changed files
with
372 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!-- | ||
Boilerplate for a functional test suite setup. | ||
This file is loosely maintained within TYPO3 testing-framework, extensions | ||
are encouraged to not use it directly, but to copy it to an own place, | ||
for instance Build/FunctionalTests.xml. | ||
Note FunctionalTestsBootstrap.php should be copied along the way. | ||
Functional tests should extend \TYPO3\TestingFramework\Core\Tests\FunctionalTestCase, | ||
take a look at this class for further documentation on how to run the suite. | ||
TYPO3 CMS functional test suite also needs phpunit bootstrap code, the | ||
file is located next to this .xml as FunctionalTestsBootstrap.php | ||
phpunit v9 compatible version, use -10.xml file for phpunit 10. | ||
--> | ||
<phpunit | ||
backupGlobals="true" | ||
bootstrap="../vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" | ||
cacheResult="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
convertDeprecationsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
forceCoversAnnotation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
verbose="false" | ||
beStrictAboutTestsThatDoNotTestAnything="false" | ||
failOnWarning="true" | ||
failOnRisky="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Functional tests"> | ||
<directory>../Tests/Functional/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<!-- @deprecated: will be removed with next major version, constant TYPO3_MODE is deprecated --> | ||
<const name="TYPO3_MODE" value="BE" /> | ||
<!-- | ||
@deprecated: Set this to not suppress warnings, notices and deprecations in functional tests | ||
with TYPO3 core v11 and up. | ||
Will always be done with next major version. | ||
To still suppress warnings, notices and deprecations, do NOT define the constant at all. | ||
--> | ||
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true" /> | ||
<ini name="display_errors" value="1" /> | ||
<env name="TYPO3_CONTEXT" value="Testing" /> | ||
</php> | ||
</phpunit> |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KayStrobach\Migrations\Tester; | ||
|
||
use KayStrobach\Migrations\Command\MigrateCommand; | ||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* Helper class to run the doctrine/migrations CLI commands within functional tests. | ||
*/ | ||
final class DoctrineCommandRunner | ||
{ | ||
private ContainerInterface $container; | ||
|
||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
public function executeMigrateCommand(): void | ||
{ | ||
$command = $this->container->get(MigrateCommand::class); | ||
$command->setHelperSet(new HelperSet([ | ||
'question' => new QuestionHelper(), | ||
])); | ||
$commandTester = new CommandTester($command); | ||
|
||
$commandTester->execute(['--no-interaction']); | ||
|
||
$commandTester->assertCommandIsSuccessful(); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
Tests/Functional/Command/Fixtures/test_migrations/Migrations/Mysql/Version20230804102700.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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KayStrobach\Migrations\TestFixtures\Migrations\Mysql; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
class Version20230804102700 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('INSERT INTO pages (title, uid, pid) VALUES ("My test page", 1, 0)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Tests/Functional/Command/Fixtures/test_migrations/composer.json
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,8 @@ | ||
{ | ||
"type": "typo3-cms-extension", | ||
"autoload": { | ||
"psr-4": { | ||
"KayStrobach\\Migrations\\TestFixtures\\Migrations\\": "Migrations/" | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Tests/Functional/Command/Fixtures/test_migrations/ext_emconf.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,19 @@ | ||
<?php | ||
|
||
$EM_CONF[$_EXTKEY] = [ | ||
'title' => 'Test migrations', | ||
'description' => 'Test migrations for testing EXT:migrations', | ||
'category' => 'service', | ||
'state' => 'alpha', | ||
'version' => '1.0.0', | ||
'author' => 'Andreas Wolf', | ||
'author_email' => '[email protected]', | ||
'constraints' => [ | ||
'depends' => [ | ||
], | ||
'conflicts' => [ | ||
], | ||
'suggests' => [ | ||
], | ||
], | ||
]; |
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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KayStrobach\Migrations\Tests\Functional\Command; | ||
|
||
use KayStrobach\Migrations\Command\MigrateCommand; | ||
use KayStrobach\Migrations\Service\DoctrineService; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
/** | ||
* @covers \KayStrobach\Migrations\Command\MigrateCommand | ||
*/ | ||
class MigrateCommandTest extends FunctionalTestCase | ||
{ | ||
protected array $testExtensionsToLoad = [ | ||
'typo3conf/ext/migrations', | ||
'typo3conf/ext/migrations/Tests/Functional/Command/Fixtures/test_migrations', | ||
]; | ||
|
||
/** @test */ | ||
public function migrationCommandExecutesMigrationsDefinedInExtensionWhenMigrationNamespaceIsRegisteredInComposer(): void | ||
{ | ||
$migrateCommand = $this->get(MigrateCommand::class); | ||
$migrateCommand->setHelperSet(new HelperSet([ | ||
'question' => new QuestionHelper(), | ||
])); | ||
$commandTester = new CommandTester($migrateCommand); | ||
|
||
$commandTester->execute(['--no-interaction']); | ||
|
||
$commandTester->assertCommandIsSuccessful(); | ||
|
||
$connection = $this->get(ConnectionPool::class) | ||
->getConnectionForTable(DoctrineService::MIGRATION_TABLE_NAME); | ||
$result = $connection->select(['*'], DoctrineService::MIGRATION_TABLE_NAME)->fetchAllAssociative(); | ||
|
||
self::assertCount(1, $result); | ||
self::assertSame('20230804102700', $result[0]['version']); | ||
|
||
$result = $connection->select(['*'], 'pages', ['uid' => 1])->fetchAllAssociative(); | ||
self::assertSame('My test page', $result[0]['title']); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Tests/Functional/Migration/AbstractDataHandlerMigrationTest.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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KayStrobach\Migrations\Tests\Functional\Migration; | ||
|
||
use KayStrobach\Migrations\Service\DoctrineService; | ||
use KayStrobach\Migrations\Tester\DoctrineCommandRunner; | ||
use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
use TYPO3\CMS\Core\Authentication\CommandLineUserAuthentication; | ||
use TYPO3\CMS\Core\Core\Bootstrap; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
/** | ||
* @covers \KayStrobach\Migrations\Migration\AbstractDataHandlerMigration | ||
*/ | ||
class AbstractDataHandlerMigrationTest extends FunctionalTestCase | ||
{ | ||
protected array $testExtensionsToLoad = [ | ||
'typo3conf/ext/migrations', | ||
'typo3conf/ext/migrations/Tests/Functional/Migration/Fixtures/test_migrations_datahandler', | ||
]; | ||
|
||
/** @test */ | ||
public function dataHandlerMigrationRunsDataHandler(): void | ||
{ | ||
Bootstrap::initializeBackendUser(CommandLineUserAuthentication::class); | ||
Bootstrap::initializeLanguageObject(); | ||
$GLOBALS['BE_USER']->workspace = 0; | ||
$this->get(DoctrineCommandRunner::class)->executeMigrateCommand(); | ||
|
||
$connection = $this->get(ConnectionPool::class) | ||
->getConnectionForTable(DoctrineService::MIGRATION_TABLE_NAME); | ||
$result = $connection->select(['*'], DoctrineService::MIGRATION_TABLE_NAME)->fetchAllAssociative(); | ||
|
||
self::assertCount(1, $result, 'No or more than one migration was executed'); | ||
self::assertSame('20230804162200', $result[0]['version']); | ||
|
||
$result = BackendUtility::getRecord('pages', 1); | ||
self::assertIsArray($result); | ||
self::assertSame('My DataHandler test page', $result['title']); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...Migration/Fixtures/test_migrations_datahandler/Migrations/Mysql/Version20230804162200.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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KayStrobach\Migrations\TestFixtures\Migrations\Mysql; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use KayStrobach\Migrations\Migration\AbstractDataHandlerMigration; | ||
|
||
class Version20230804162200 extends AbstractDataHandlerMigration | ||
{ | ||
public function preUp(Schema $schema): void | ||
{ | ||
parent::preUp($schema); | ||
|
||
$this->dataMap = [ | ||
'pages' => [ | ||
'NEW1234' => [ | ||
'pid' => 0, | ||
'title' => 'My DataHandler test page', | ||
], | ||
], | ||
]; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Tests/Functional/Migration/Fixtures/test_migrations_datahandler/composer.json
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,8 @@ | ||
{ | ||
"type": "typo3-cms-extension", | ||
"autoload": { | ||
"psr-4": { | ||
"KayStrobach\\Migrations\\TestFixtures\\Migrations\\": "Migrations/" | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Tests/Functional/Migration/Fixtures/test_migrations_datahandler/ext_emconf.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,19 @@ | ||
<?php | ||
|
||
$EM_CONF[$_EXTKEY] = [ | ||
'title' => 'Test migrations', | ||
'description' => 'Test migrations for testing EXT:migrations', | ||
'category' => 'service', | ||
'state' => 'alpha', | ||
'version' => '1.0.0', | ||
'author' => 'Andreas Wolf', | ||
'author_email' => '[email protected]', | ||
'constraints' => [ | ||
'depends' => [ | ||
], | ||
'conflicts' => [ | ||
], | ||
'suggests' => [ | ||
], | ||
], | ||
]; |
Oops, something went wrong.