diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ed2a1e4..62180330 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,12 @@ +--- + name: build on: # yamllint disable-line rule:truthy - pull_request: push: - branches: [4.x] + branches: + - 4.x + pull_request: null permissions: contents: read @@ -13,53 +16,11 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - test: - name: Test PHP ${{ matrix.php-version }} (${{ matrix.dependencies }}) - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - php-version: ['8.2', '8.3', '8.4', '8.5'] - dependencies: [lowest, highest] - steps: - - name: Install ODBC driver. - run: | - sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list - sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 - - - name: Checkout - uses: actions/checkout@v7 - with: - persist-credentials: false - - - name: Setup DB services - run: | - cd tests - docker compose up -d - cd .. - - - name: Setup PHP ${{ matrix.php-version }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - coverage: pcov - tools: pecl - extensions: mbstring, pdo, pdo_sqlite, pdo_pgsql, pdo_sqlsrv, pdo_mysql - - - name: Validate composer.json - run: composer validate --ansi --strict - - - name: Install dependencies with composer - uses: ramsey/composer-install@v4 - with: - dependency-versions: ${{ matrix.dependencies }} - - - name: Execute Tests - run: vendor/bin/phpunit --coverage-clover=coverage.clover - - - name: Upload coverage to Codecov - continue-on-error: true # if is fork - uses: codecov/codecov-action@v7 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage.clover + testo: + name: Testo + uses: cycle/gh-actions/.github/workflows/testo.yml@master + with: + coverage: true + secrets: inherit + +... diff --git a/README.md b/README.md index 0a5f0c64..610654d0 100644 --- a/README.md +++ b/README.md @@ -371,3 +371,18 @@ composer require --dev llm/skills ``` Querying and persisting the mapped entities is covered by the `cycle-orm` skill that comes with [cycle/orm](https://github.com/cycle/orm). + +## Testing + +The tests run on [Testo](https://github.com/php-testo/testo) through the shared [cycle/testing](https://github.com/cycle/testing) harness: `tests/Unit` needs no database, and `tests/Feature` runs once per database driver. + +```bash +composer test:unit # no database +composer test:sqlite # in-memory SQLite, no docker +composer db:up # MySQL, Postgres and SQL Server in docker +composer test # every suite; a driver whose server is down is skipped +composer db:down +``` + +`composer test:mysql`, `test:postgres` and `test:sqlserver` run one driver. To reproduce a new issue, generate a case: +`composer test:new-case -- 123` writes `tests/Regression/Issue123`. diff --git a/composer.json b/composer.json index 3a34689a..3770a5e6 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,12 @@ "url": "https://github.com/sponsors/cycle" } ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/cycle/testing" + } + ], "require": { "php": ">=8.2", "cycle/database": "^2.23", @@ -48,10 +54,11 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8", "buggregator/trap": "^1.20", + "cycle/testing": "^0.1.1", "doctrine/annotations": "^2.0.2", "llm/skills": "^1.20", - "phpunit/phpunit": "^11.5", - "roxblnfk/unpoly": "^1.8" + "roxblnfk/unpoly": "^1.8", + "testo/testo": "^0.10.60" }, "suggest": { "llm/skills": "To sync the cycle-orm-attributes AI skill into your project" @@ -63,7 +70,7 @@ }, "autoload-dev": { "psr-4": { - "Cycle\\Annotated\\Tests\\": "tests/Annotated/" + "Cycle\\Annotated\\Tests\\": "tests/" } }, "scripts": { @@ -72,7 +79,18 @@ "psalm": "psalm -c vendor-bin/psalm/psalm.xml", "psalm:baseline": "psalm -c vendor-bin/psalm/psalm.xml --set-baseline=vendor-bin/psalm/psalm-baseline.xml", "psalm:ci": "psalm -c vendor-bin/psalm/psalm.xml --output-format=github --shepherd --show-info=false --stats --threads=4", - "test": "phpunit --color=always" + "db:down": "docker compose -f vendor/cycle/testing/resources/docker/compose.yaml down -v", + "db:up": "docker compose -f vendor/cycle/testing/resources/docker/compose.yaml up -d --wait", + "test": "testo", + "test:mysql": "testo --suite=Feature/MySQL --suite=Acceptance/MySQL --suite=Regression/MySQL", + "test:new-case": "cycle-testing new-case --template=orm-attributes", + "test:postgres": "testo --suite=Feature/Postgres --suite=Acceptance/Postgres --suite=Regression/Postgres", + "test:sqlite": "testo --suite=Feature/SQLite --suite=Acceptance/SQLite --suite=Regression/SQLite", + "test:sqlserver": "testo --suite=Feature/SQLServer --suite=Acceptance/SQLServer --suite=Regression/SQLServer", + "test:unit": "testo --suite=Unit" + }, + "scripts-descriptions": { + "test:new-case": "Create a regression case for an issue: composer test:new-case -- " }, "extra": { "bamarni-bin": { diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index d3e3efdc..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - src/ - - - - - ./tests/ - - - diff --git a/testo.php b/testo.php new file mode 100644 index 00000000..bd8e6bdf --- /dev/null +++ b/testo.php @@ -0,0 +1,17 @@ +unit('tests/Unit') + ->feature( + 'tests/Feature', + layout: Layout::prefixed(['secondary' => 'secondary_']), + plugins: [new OrmPlugin()], + ) + ->regression('tests/Regression', plugins: [new OrmPlugin()]) + ->build(); diff --git a/tests/Annotated/Fixtures/Fixtures1/TestLogger.php b/tests/Annotated/Fixtures/Fixtures1/TestLogger.php deleted file mode 100644 index 03840cf4..00000000 --- a/tests/Annotated/Fixtures/Fixtures1/TestLogger.php +++ /dev/null @@ -1,105 +0,0 @@ -countWrites = 0; - $this->countReads = 0; - } - - public function countWriteQueries(): int - { - return $this->countWrites; - } - - public function countReadQueries(): int - { - return $this->countReads; - } - - public function log($level, $message, array $context = []): void - { - if (!empty($context['query'])) { - $sql = strtolower($context['query']); - if ( - strpos($sql, 'insert') === 0 - || strpos($sql, 'update') === 0 - || strpos($sql, 'delete') === 0 - ) { - $this->countWrites++; - } else { - if (!$this->isPostgresSystemQuery($sql)) { - $this->countReads++; - } - } - } - - if (!$this->display) { - return; - } - - if ($level == LogLevel::ERROR) { - echo " \n! \033[31m" . $message . "\033[0m"; - } elseif ($level == LogLevel::ALERT) { - echo " \n! \033[35m" . $message . "\033[0m"; - } elseif (strpos($message, 'SHOW') === 0) { - echo " \n> \033[34m" . $message . "\033[0m"; - } else { - if ($this->isPostgresSystemQuery($message)) { - echo " \n> \033[90m" . $message . "\033[0m"; - - return; - } - - if (strpos($message, 'SELECT') === 0) { - echo " \n> \033[32m" . $message . "\033[0m"; - } elseif (strpos($message, 'INSERT') === 0) { - echo " \n> \033[36m" . $message . "\033[0m"; - } else { - echo " \n> \033[33m" . $message . "\033[0m"; - } - } - } - - public function display(): void - { - $this->display = true; - } - - public function hide(): void - { - $this->display = false; - } - - protected function isPostgresSystemQuery(string $query): bool - { - $query = strtolower($query); - return (bool) ( - strpos($query, 'tc.constraint_name') - || strpos($query, 'pg_indexes') - || strpos($query, 'tc.constraint_name') - || strpos($query, 'pg_constraint') - || strpos($query, 'information_schema') - || strpos($query, 'pg_class') - ) - - - - ; - } -} diff --git a/tests/Annotated/Functional/Driver/Common/BaseTestCase.php b/tests/Annotated/Functional/Driver/Common/BaseTestCase.php deleted file mode 100644 index bbe78715..00000000 --- a/tests/Annotated/Functional/Driver/Common/BaseTestCase.php +++ /dev/null @@ -1,168 +0,0 @@ - [new AnnotationReader()]; - yield 'Attribute reader' => [new AttributeReader()]; - } - - public static function allReadersProvider(): \Traversable - { - yield from static::singularReadersProvider(); - yield 'Selective reader' => [new SelectiveReader([new AttributeReader(), new AnnotationReader()])]; - } - - public function getDriver(): Driver - { - if (isset(static::$driverCache[static::DRIVER])) { - return static::$driverCache[static::DRIVER]; - } - - $config = self::$config[static::DRIVER]; - if (!isset($this->driver)) { - $this->driver = $config->driver::create($config); - } - - $this->driver->setProfiling(true); - - return static::$driverCache[static::DRIVER] = $this->driver; - } - - /** - * Init all we need. - */ - public function setUp(): void - { - parent::setUp(); - - $this->dbal = new DatabaseManager(new DatabaseConfig(['default' => 'default'])); - $this->dbal->addDatabase(new Database( - 'default', - '', - $this->getDriver(), - )); - - $this->dbal->addDatabase(new Database( - 'secondary', - 'secondary_', - $this->getDriver(), - )); - - $this->logger = new TestLogger(); - $this->getDriver()->setLogger($this->logger); - - if (self::$config['debug']) { - $this->logger->display(); - } - - $this->logger = new TestLogger(); - $this->getDriver()->setLogger($this->logger); - - if (self::$config['debug']) { - $this->logger->display(); - } - - $this->orm = new ORM(new Factory( - $this->dbal, - RelationConfig::getDefault(), - ), new Schema([])); - - $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures1'], - 'exclude' => [], - ])); - - $this->locator = $tokenizer->classLocator(); - } - - /** - * Cleanup. - */ - public function tearDown(): void - { - $this->disableProfiling(); - $this->dropDatabase($this->dbal->database('default')); - } - - protected function getDatabase(): Database - { - return $this->dbal->database('default'); - } - - protected function dropDatabase(?Database $database = null): void - { - if (empty($database)) { - return; - } - - foreach ($database->getTables() as $table) { - $schema = $table->getSchema(); - - foreach ($schema->getForeignKeys() as $foreign) { - $schema->dropForeignKey($foreign->getColumns()); - } - - $schema->save(Handler::DROP_FOREIGN_KEYS); - } - - foreach ($database->getTables() as $table) { - $schema = $table->getSchema(); - $schema->declareDropped(); - $schema->save(); - } - } - - /** - * For debug purposes only. - */ - protected function enableProfiling(): void - { - $this->logger->display(); - } - - /** - * For debug purposes only. - */ - protected function disableProfiling(): void - { - $this->logger->hide(); - } -} diff --git a/tests/Annotated/Functional/Driver/Common/Inheritance/SingleTableTestCase.php b/tests/Annotated/Functional/Driver/Common/Inheritance/SingleTableTestCase.php deleted file mode 100644 index cde14b95..00000000 --- a/tests/Annotated/Functional/Driver/Common/Inheritance/SingleTableTestCase.php +++ /dev/null @@ -1,359 +0,0 @@ - [__DIR__ . '/../../../../Fixtures/Fixtures16'], - 'exclude' => [], - ]), - ); - - $locator = $tokenizer->classLocator(); - - $r = new Registry($this->dbal); - - $schema = (new Compiler())->compile($r, [ - new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), - new Entities(new TokenizerEntityLocator($locator, $reader), $reader), - new TableInheritance($reader), - new ResetTables(), - new MergeColumns($reader), - new GenerateRelations(), - new RenderTables(), - new RenderRelations(), - new MergeIndexes($reader), - new SyncTables(), - new GenerateTypecast(), - ]); - - $this->orm = $this->orm->with(new Schema($schema)); - - $t = new EntityManager($this->orm); - - $employee = new Employee(); - $employee->name = 'foo'; - $employee->salary = 12500; - $employee->bar = 'test'; - - $employee1 = new Employee(); - $employee1->name = 'bar'; - $employee1->salary = 23000; - - $person = new Person(); - $person->name = 'baz'; - - $customer = new Customer(); - $customer->name = 'baz'; - $customer->preferences = 'private'; - - $ceo = new Ceo(); - $ceo->name = 'ceo'; - $ceo->stocks = 1000; - $ceo->salary = 150000; - - $t->persist($employee); - $t->persist($employee1); - $t->persist($person); - $t->persist($customer); - $t->persist($ceo); - - $t->run(); - - $this->orm->getHeap()->clean(); - - $this->assertNotNull($person->getFooId()); - $loadedPerson = $this->orm->getRepository(Person::class)->findByPK($person->getFooId()); - $this->assertInstanceOf(Person::class, $loadedPerson); - $this->assertSame('baz', $loadedPerson->name); - $this->assertFalse(isset($loadedPerson->preferences)); - $this->assertFalse(isset($loadedPerson->salary)); - - $this->assertNotNull($employee->getFooId()); - $loadedEmployee = $this->orm->getRepository(Person::class)->findByPK($employee->getFooId()); - $this->assertInstanceOf(Employee::class, $loadedEmployee); - $this->assertSame('foo', $loadedEmployee->name); - $this->assertSame(12500, $loadedEmployee->salary); - $this->assertSame('test', $loadedEmployee->bar); - $this->assertFalse(isset($loadedEmployee->preferences)); - - $this->assertNotNull($customer->getFooId()); - $loadedCustomer = $this->orm->getRepository(Person::class)->findByPK($customer->getFooId()); - $this->assertInstanceOf(Customer::class, $loadedCustomer); - $this->assertSame('baz', $loadedCustomer->name); - $this->assertSame('private', $loadedCustomer->preferences); - $this->assertFalse(isset($loadedCustomer->salary)); - - $this->assertNotNull($ceo->getFooId()); - $loadedCeo = $this->orm->getRepository(Ceo::class)->findByPK($ceo->getFooId()); - $this->assertInstanceOf(Ceo::class, $loadedCeo); - $this->assertSame('ceo', $loadedCeo->name); - $this->assertSame(150000, $loadedCeo->salary); - $this->assertSame(1000, $loadedCeo->stocks); - } - - #[DataProvider('allReadersProvider')] - public function testTableInheritanceSchema(ReaderInterface $reader): void - { - $tokenizer = new Tokenizer( - new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures20'], - 'exclude' => [], - ]), - ); - - $locator = $tokenizer->classLocator(); - - $r = new Registry($this->dbal); - - $schema = (new Compiler())->compile($r, [ - new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), - new Entities(new TokenizerEntityLocator($locator, $reader), $reader), - new TableInheritance($reader), - new ResetTables(), - new MergeColumns($reader), - new GenerateRelations(), - new RenderTables(), - new RenderRelations(), - new MergeIndexes($reader), - new GenerateTypecast(), - ]); - - $this->assertNotEmpty($schema); - - $this->assertArrayHasKey(SchemaInterface::CHILDREN, $schema['person']); - $this->assertArrayHasKey(SchemaInterface::DISCRIMINATOR, $schema['person']); - $this->assertSame('type', $schema['person'][SchemaInterface::DISCRIMINATOR]); - - $this->assertArrayHasKey(SchemaInterface::PARENT, $schema['buyer']); - $this->assertArrayHasKey(SchemaInterface::PARENT_KEY, $schema['buyer']); - } - - #[DataProvider('columnDeclarationWithReadersDataProvider')] - public function testSingleTableInheritanceWithDifferentColumnDeclaration( - string $directory, - string $namespace, - ReaderInterface $reader, - ): void { - $tokenizer = new Tokenizer( - new TokenizerConfig([ - 'directories' => [$directory], - 'exclude' => [], - ]), - ); - - $locator = $tokenizer->classLocator(); - - $r = new Registry($this->dbal); - - $schema = (new Compiler())->compile($r, [ - new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), - new Entities(new TokenizerEntityLocator($locator, $reader), $reader), - new MergeColumns($reader), - new TableInheritance($reader), - new ResetTables(), - new GenerateRelations(), - new RenderTables(), - new RenderRelations(), - new MergeIndexes($reader), - new GenerateTypecast(), - ]); - - $this->assertNotEmpty($schema); - $this->assertSame(\sprintf( - 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\BaseEvent', - $namespace, - ), $schema['baseEvent'][SchemaInterface::ENTITY]); - $this->assertSame(Mapper::class, $schema['baseEvent'][SchemaInterface::MAPPER]); - $this->assertSame(Source::class, $schema['baseEvent'][SchemaInterface::SOURCE]); - $this->assertSame(Repository::class, $schema['baseEvent'][SchemaInterface::REPOSITORY]); - $this->assertSame('default', $schema['baseEvent'][SchemaInterface::DATABASE]); - $this->assertSame('base_events', $schema['baseEvent'][SchemaInterface::TABLE]); - $this->assertSame(['id'], $schema['baseEvent'][SchemaInterface::PRIMARY_KEY]); - $this->assertSame(['id'], $schema['baseEvent'][SchemaInterface::FIND_BY_KEYS]); - $this->assertCount(4, $schema['baseEvent'][SchemaInterface::COLUMNS]); - $this->assertSame('id', $schema['baseEvent'][SchemaInterface::COLUMNS]['id']); - $this->assertSame('action', $schema['baseEvent'][SchemaInterface::COLUMNS]['action']); - $this->assertSame('object_id', $schema['baseEvent'][SchemaInterface::COLUMNS]['object_id']); - $this->assertSame('object_type', $schema['baseEvent'][SchemaInterface::COLUMNS]['object_type']); - $this->assertSame( - Relation::BELONGS_TO_MORPHED, - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::TYPE], - ); - $this->assertSame( - \sprintf('Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\EventEmitterInterface', $namespace), - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::TARGET], - ); - $this->assertSame( - Relation::LOAD_PROMISE, - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::LOAD], - ); - $this->assertTrue( - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::CASCADE], - ); - $this->assertTrue( - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::NULLABLE], - ); - $this->assertSame( - ['id'], - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::OUTER_KEY], - ); - $this->assertSame( - 'object_id', - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::INNER_KEY], - ); - $this->assertSame( - 'object_type', - $schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::MORPH_KEY], - ); - $this->assertCount(2, $schema['baseEvent'][SchemaInterface::CHILDREN]); - $this->assertSame( - \sprintf('Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentCreated', $namespace), - $schema['baseEvent'][SchemaInterface::CHILDREN]['comment.created'], - ); - $this->assertSame( - \sprintf('Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentUpdated', $namespace), - $schema['baseEvent'][SchemaInterface::CHILDREN]['comment.updated'], - ); - $this->assertNull($schema['baseEvent'][SchemaInterface::SCOPE]); - $this->assertSame('int', $schema['baseEvent'][SchemaInterface::TYPECAST]['id']); - $this->assertSame('int', $schema['baseEvent'][SchemaInterface::TYPECAST]['object_id']); - $this->assertSame([], $schema['baseEvent'][SchemaInterface::SCHEMA]); - $this->assertSame('action', $schema['baseEvent'][SchemaInterface::DISCRIMINATOR]); - $this->assertNull($schema['baseEvent'][SchemaInterface::TYPECAST_HANDLER]); - $this->assertSame( - [ - SchemaInterface::ENTITY => \sprintf( - 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\Comment', - $namespace, - ), - SchemaInterface::MAPPER => Mapper::class, - SchemaInterface::SOURCE => Source::class, - SchemaInterface::REPOSITORY => Repository::class, - SchemaInterface::DATABASE => 'default', - SchemaInterface::TABLE => 'comments', - SchemaInterface::PRIMARY_KEY => [ - 'id', - ], - SchemaInterface::FIND_BY_KEYS => [ - 'id', - ], - SchemaInterface::COLUMNS => [ - 'id' => 'id', - 'body' => 'body', - ], - SchemaInterface::RELATIONS => [], - SchemaInterface::SCOPE => null, - SchemaInterface::TYPECAST => [ - 'id' => 'int', - 'body' => 'string', - ], - SchemaInterface::SCHEMA => [], - SchemaInterface::TYPECAST_HANDLER => null, - SchemaInterface::GENERATED_FIELDS => [ - 'id' => GeneratedField::ON_INSERT, - ], - ], - $schema['comment'], - ); - $this->assertSame([ - SchemaInterface::ENTITY => \sprintf( - 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentCreated', - $namespace, - ), - ], $schema['commentCreated']); - $this->assertSame([ - SchemaInterface::ENTITY => \sprintf( - 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentUpdated', - $namespace, - ), - ], $schema['commentUpdated']); - } - - public function setUp(): void - { - parent::setUp(); - - $this->makeTable('people', [ - 'id' => 'primary', - 'type' => 'string', - 'name' => 'string', - 'salary' => 'float', - 'preferences' => 'string', - 'bar' => 'string', - 'stocks' => 'int', - ]); - } -} diff --git a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/MorphedHasManyTestCase.php b/tests/Annotated/Functional/Driver/Common/Relation/Morphed/MorphedHasManyTestCase.php deleted file mode 100644 index b5233482..00000000 --- a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/MorphedHasManyTestCase.php +++ /dev/null @@ -1,86 +0,0 @@ -dbal); - - $schema = (new Compiler())->compile($r, [ - new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader), - new ResetTables(), - new MergeColumns($reader), - new GenerateRelations(), - new RenderTables(), - new RenderRelations(), - new MergeIndexes($reader), - new SyncTables(), - new GenerateTypecast(), - ]); - - $this->assertArrayHasKey('labels', $schema['simple'][Schema::RELATIONS]); - $this->assertSame( - Relation::MORPHED_HAS_MANY, - $schema['simple'][Schema::RELATIONS]['labels'][Relation::TYPE], - ); - $this->assertSame('label', $schema['simple'][Schema::RELATIONS]['labels'][Relation::TARGET]); - - $this->assertArrayHasKey('labels', $schema['withTable'][Schema::RELATIONS]); - $this->assertSame( - Relation::MORPHED_HAS_MANY, - $schema['withTable'][Schema::RELATIONS]['labels'][Relation::TYPE], - ); - - $this->assertSame('label', $schema['withTable'][Schema::RELATIONS]['labels'][Relation::TARGET]); - - $this->assertTrue( - $this->dbal->database('default') - ->getDriver() - ->getSchema('labels') - ->hasColumn('owner_id'), - ); - - $this->assertTrue( - $this->dbal->database('default') - ->getDriver() - ->getSchema('labels') - ->hasColumn('owner_role'), - ); - - $this->assertFalse( - $this->dbal->database('default') - ->getDriver() - ->getSchema('labels') - ->hasIndex(['owner_id', 'owner_role']), - ); - - $this->assertSame( - BaseCollection::class, - $schema['simple'][\Cycle\ORM\SchemaInterface::RELATIONS]['labels'][Relation::SCHEMA][Relation::COLLECTION_TYPE], // phpcs:ignore - ); - } -} diff --git a/tests/Annotated/Functional/Driver/MySQL/ChildTest.php b/tests/Annotated/Functional/Driver/MySQL/ChildTest.php deleted file mode 100644 index c12aaaee..00000000 --- a/tests/Annotated/Functional/Driver/MySQL/ChildTest.php +++ /dev/null @@ -1,16 +0,0 @@ - [__DIR__ . '/../../../Fixtures/Fixtures25/PostgreSQL'], - 'exclude' => [], - ])); - - $locator = $tokenizer->classLocator(); - - $r = new Registry($this->dbal); - - $schema = (new Compiler())->compile($r, [ - new Entities(new TokenizerEntityLocator($locator, $reader), $reader), - ]); - - $this->assertSame( - [ - 'id' => GeneratedField::ON_INSERT, - 'smallSerial' => GeneratedField::ON_INSERT, - 'serial' => GeneratedField::ON_INSERT, - 'bigSerial' => GeneratedField::ON_INSERT, - ], - $schema['withGeneratedSerial'][SchemaInterface::GENERATED_FIELDS], - ); - } -} diff --git a/tests/Annotated/Functional/Driver/Postgres/GeneratorTest.php b/tests/Annotated/Functional/Driver/Postgres/GeneratorTest.php deleted file mode 100644 index facb38f2..00000000 --- a/tests/Annotated/Functional/Driver/Postgres/GeneratorTest.php +++ /dev/null @@ -1,16 +0,0 @@ -getDatabase()->table($table)->getSchema(); - $renderer = new TableRenderer(); - $renderer->renderColumns($schema, $columns, $defaults); - - foreach ($fk as $column => $options) { - if (isset($options['from'])) { - $column = $options['from']; - } - $fkState = $schema->foreignKey((array) $column)->references($options['table'], (array) $options['column']); - $fkState->onUpdate($options['onUpdate'] ?? ForeignKeyInterface::CASCADE); - $fkState->onDelete($options['onDelete'] ?? ForeignKeyInterface::CASCADE); - } - - if (!empty($pk)) { - $schema->setPrimaryKeys($pk); - } - - $schema->save(); - } - - public function makeFK( - string $from, - string|array $fromKey, - string $to, - string|array $toColumn, - string $onDelete = ForeignKeyInterface::CASCADE, - string $onUpdate = ForeignKeyInterface::CASCADE, - ): void { - $schema = $this->getDatabase()->table($from)->getSchema(); - $schema->foreignKey((array) $fromKey) - ->references($to, (array) $toColumn) - ->onDelete($onDelete) - ->onUpdate($onUpdate); - $schema->save(); - } - - public function makeCompositeFK( - string $from, - array $fromKeys, - string $to, - array $toColumns, - string $onDelete = ForeignKeyInterface::CASCADE, - string $onUpdate = ForeignKeyInterface::CASCADE, - ): void { - $schema = $this->getDatabase()->table($from)->getSchema(); - $schema->foreignKey($fromKeys)->references($to, $toColumns)->onDelete($onDelete)->onUpdate($onUpdate); - $schema->save(); - } - - public function makeIndex( - string $table, - array $columns, - bool $unique, - ): void { - $schema = $this->getDatabase()->table($table)->getSchema(); - $schema->index($columns)->unique($unique); - $schema->save(); - } - - abstract protected function getDatabase(): Database; -} diff --git a/tests/Annotated/Util/TableRenderer.php b/tests/Annotated/Util/TableRenderer.php deleted file mode 100644 index c87a1afb..00000000 --- a/tests/Annotated/Util/TableRenderer.php +++ /dev/null @@ -1,193 +0,0 @@ - 'primary', - * 'time' => 'datetime, nullable', - * 'status' => 'enum(active, disabled)' - * ], - * [ - * 'status' => 'active', - * 'time' => null, - * ] - * ); - * - * @throws SchemaException - */ - public function renderColumns(AbstractTable $table, array $columns, array $defaults): void - { - $primaryKeys = []; - foreach ($columns as $name => $definition) { - $type = $this->parse($table->getName(), $name, $definition); - - if ($this->hasFlag($type, 'primary')) { - $primaryKeys[] = $name; - } - - $this->renderColumn( - $table->column($name), - $type, - array_key_exists($name, $defaults), - $defaults[$name] ?? null, - ); - } - - if (count($primaryKeys)) { - $table->setPrimaryKeys($primaryKeys); - } - } - - /** - * Cast (specify) column schema based on provided column definition and default value. - * Spiral will force default values (internally) for every NOT NULL column except primary keys! - * - * Column definition are compatible with database Migrations and AbstractColumn types. - * - * Column definition examples (by default all columns has flag NOT NULL): - * const SCHEMA = [ - * 'id' => 'primary', - * 'name' => 'string', //Default length is 255 characters. - * 'email' => 'string(255), nullable', //Can be NULL - * 'status' => 'enum(active, pending, disabled)', //Enum values, trimmed - * 'balance' => 'decimal(10, 2)', - * 'message' => 'text, null', //Alias for nullable - * 'time_expired' => 'timestamp' - * ]; - * - * Attention, column state will be affected! - * - * @param bool $hasDefault Must be set to true if default value was set by user. - * @param mixed $default Default value declared by record schema. - * - * @throws SchemaException - * - * @see AbstractColumn - */ - protected function renderColumn(AbstractColumn $column, array $type, bool $hasDefault, $default = null): void - { - // ORM force EVERY column to NOT NULL state unless different is said - $column->nullable(false); - - if ($this->hasFlag($type, 'null') || $this->hasFlag($type, 'nullable')) { - // indication that column is nullable - $column->nullable(true); - } - - try { - // bypassing call to AbstractColumn->__call method (or specialized column method) - call_user_func_array([$column, $type['type']], $type['options']); - } catch (\Throwable $e) { - throw new SchemaException( - "Invalid column type definition in '{$column->getTable()}'.'{$column->getName()}'", - $e->getCode(), - $e, - ); - } - - if (in_array($column->getAbstractType(), ['primary', 'bigPrimary'])) { - // no default value can be set of primary keys - return; - } - - if (!$hasDefault && !$column->isNullable()) { - if (!$this->hasFlag($type, 'required') && !$this->hasFlag($type, 'primary')) { - // we have to come up with some default value - $column->defaultValue($this->castDefault($column)); - } - - return; - } - - if ($default === null) { - // default value is stated and NULL, clear what to do - $column->nullable(true); - } - - $column->defaultValue($default); - } - - protected function parse(string $table, string $column, string $definition): array - { - if ( - !preg_match( - '/(?P[a-z]+)(?: *\((?P[^\)]+)\))?(?: *, *(?P.+))?/i', - $definition, - $type, - ) - ) { - throw new SchemaException("Invalid column type definition in '{$table}'.'{$column}'"); - } - - if (empty($type['options'])) { - $type['options'] = []; - } else { - $type['options'] = array_map('trim', explode(',', $type['options'] ?? '')); - } - - if (empty($type['flags'])) { - $type['flags'] = []; - } else { - $type['flags'] = array_map('trim', explode(',', $type['flags'] ?? '')); - } - - unset($type[0], $type[1], $type[2], $type[3]); - - return $type; - } - - protected function hasFlag(array $type, string $flag): bool - { - return in_array($flag, $type['flags'], true); - } - - /** - * Cast default value based on column type. Required to prevent conflicts when not nullable - * column added to existed table with data in. - * - * @return mixed - */ - protected function castDefault(AbstractColumn $column) - { - if (in_array($column->getAbstractType(), ['timestamp', 'datetime', 'time', 'date'])) { - return 0; - } - - if ($column->getAbstractType() == 'enum') { - // we can use first enum value as default - return $column->getEnumValues()[0]; - } - - switch ($column->getType()) { - case 'int': - return 0; - case 'float': - return 0.0; - case 'bool': - return false; - } - - return ''; - } -} diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/BaseTestCase.php new file mode 100644 index 00000000..29077f8b --- /dev/null +++ b/tests/Feature/BaseTestCase.php @@ -0,0 +1,42 @@ + [new AnnotationReader()]; + yield 'Attribute reader' => [new AttributeReader()]; + } + + public static function allReadersProvider(): \Traversable + { + yield from static::singularReadersProvider(); + yield 'Selective reader' => [new SelectiveReader([new AttributeReader(), new AnnotationReader()])]; + } + + #[BeforeTest] + public function initLocator(): void + { + $tokenizer = new Tokenizer(new TokenizerConfig([ + 'directories' => [__DIR__ . '/../Fixtures/Fixtures1'], + 'exclude' => [], + ])); + + $this->locator = $tokenizer->classLocator(); + } +} diff --git a/tests/Annotated/Functional/Driver/Common/ChildTestCase.php b/tests/Feature/Common/ChildTest.php similarity index 82% rename from tests/Annotated/Functional/Driver/Common/ChildTestCase.php rename to tests/Feature/Common/ChildTest.php index 69a126db..f086a075 100644 --- a/tests/Annotated/Functional/Driver/Common/ChildTestCase.php +++ b/tests/Feature/Common/ChildTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -10,6 +10,7 @@ use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Child; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Simple; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Third; @@ -23,12 +24,14 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class ChildTestCase extends BaseTestCase +final class ChildTest extends BaseTestCase { // /** // * @dataProvider allReadersProvider @@ -53,10 +56,11 @@ abstract class ChildTestCase extends BaseTestCase // } #[DataProvider('allReadersProvider')] + #[Test] public function testRelationToChild(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures8'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures8'], 'exclude' => [], ])); @@ -77,9 +81,9 @@ public function testRelationToChild(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('article', $schema['some'][Schema::RELATIONS]); - $this->assertSame(Relation::HAS_ONE, $schema['some'][Schema::RELATIONS]['article'][Relation::TYPE]); + Assert::array($schema['some'][Schema::RELATIONS])->hasKeys('article'); + Assert::same($schema['some'][Schema::RELATIONS]['article'][Relation::TYPE], Relation::HAS_ONE); - $this->assertSame('post', $schema['some'][Schema::RELATIONS]['article'][Relation::TARGET]); + Assert::same($schema['some'][Schema::RELATIONS]['article'][Relation::TARGET], 'post'); } } diff --git a/tests/Annotated/Functional/Driver/Common/CompositePkGeneratedTestCase.php b/tests/Feature/Common/CompositePkGeneratedTest.php similarity index 74% rename from tests/Annotated/Functional/Driver/Common/CompositePkGeneratedTestCase.php rename to tests/Feature/Common/CompositePkGeneratedTest.php index 38fb7d68..fbd5eb33 100644 --- a/tests/Annotated/Functional/Driver/Common/CompositePkGeneratedTestCase.php +++ b/tests/Feature/Common/CompositePkGeneratedTest.php @@ -2,12 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures28\Event; use Cycle\ORM\Config\RelationConfig; use Cycle\ORM\EntityManager; @@ -25,10 +26,14 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; +use Cycle\Testing\Database\Attribute\OnlyDriver; +use Cycle\Testing\Database\Driver; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; /** * Composite primary key where one part is application-supplied (uuid) and the @@ -36,37 +41,33 @@ * * Mirrors cycle/orm "Case8" but driven entirely by attributes/annotations. * The round-trip relies on a driver implementing ReturningInterface - * (PostgreSQL, SQL Server), so it lives in those driver suites. + * (PostgreSQL, SQL Server), so it runs only on those drivers. */ -abstract class CompositePkGeneratedTestCase extends BaseTestCase +#[OnlyDriver(Driver::Postgres, Driver::SQLServer)] +final class CompositePkGeneratedTest extends BaseTestCase { /** * The composite PK and the database-generated component must be derived * from the attributes alone. */ #[DataProvider('allReadersProvider')] + #[Test] public function testCompositePkSchema(ReaderInterface $reader): void { $schema = $this->compile($reader); - $this->assertSame(['parentId', 'id'], $schema['event'][SchemaInterface::PRIMARY_KEY]); - $this->assertSame( - ['parentId' => 'parent_id', 'id' => 'id', 'payload' => 'payload'], - $schema['event'][SchemaInterface::COLUMNS], - ); + Assert::same($schema['event'][SchemaInterface::PRIMARY_KEY], ['parentId', 'id']); + Assert::same($schema['event'][SchemaInterface::COLUMNS], ['parentId' => 'parent_id', 'id' => 'id', 'payload' => 'payload']); // Both primary columns are flagged ON_INSERT: the bigserial `id` is // genuinely database-generated, while the app-supplied uuid `parentId` // is auto-flagged purely because it is primary (see Event::$parentId // and Configurator::isOnInsertGeneratedField()). The parentId flag only // echoes the value back via RETURNING — harmless for a uuid string. - $this->assertSame( - [ - 'parentId' => GeneratedField::ON_INSERT, - 'id' => GeneratedField::ON_INSERT, - ], - $schema['event'][SchemaInterface::GENERATED_FIELDS], - ); + Assert::same($schema['event'][SchemaInterface::GENERATED_FIELDS], [ + 'parentId' => GeneratedField::ON_INSERT, + 'id' => GeneratedField::ON_INSERT, + ]); } /** @@ -75,6 +76,7 @@ public function testCompositePkSchema(ReaderInterface $reader): void * the full composite key. */ #[DataProvider('allReadersProvider')] + #[Test] public function testCreateGeneratesIdAndFetchByCompositePk(ReaderInterface $reader): void { $orm = new ORM( @@ -95,9 +97,9 @@ public function testCreateGeneratesIdAndFetchByCompositePk(ReaderInterface $read (new EntityManager($orm))->persist($first)->persist($second)->run(); // database-generated ids - $this->assertIsInt($first->id); - $this->assertIsInt($second->id); - $this->assertNotSame($first->id, $second->id); + Assert::int($first->id); + Assert::int($second->id); + Assert::notSame($second->id, $first->id); // fetch by the full composite key $found = (new Select($orm, Event::class)) @@ -105,15 +107,15 @@ public function testCreateGeneratesIdAndFetchByCompositePk(ReaderInterface $read ->where('id', $second->id) ->fetchOne(); - $this->assertNotNull($found); - $this->assertSame('second', $found->payload); - $this->assertSame($second, $found, 'Heap returns the same identity for the composite key.'); + Assert::notNull($found); + Assert::same($found->payload, 'second'); + Assert::same($found, $second, 'Heap returns the same identity for the composite key.'); } private function compile(ReaderInterface $reader): array { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures28'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures28'], 'exclude' => [], ])); diff --git a/tests/Annotated/Functional/Driver/Common/GeneratedFieldsTestCase.php b/tests/Feature/Common/GeneratedFieldsTest.php similarity index 55% rename from tests/Annotated/Functional/Driver/Common/GeneratedFieldsTestCase.php rename to tests/Feature/Common/GeneratedFieldsTest.php index 7ef6dd04..a41dd551 100644 --- a/tests/Annotated/Functional/Driver/Common/GeneratedFieldsTestCase.php +++ b/tests/Feature/Common/GeneratedFieldsTest.php @@ -2,26 +2,30 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Schema\GeneratedField; use Cycle\ORM\SchemaInterface; use Cycle\Schema\Compiler; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class GeneratedFieldsTestCase extends BaseTestCase +final class GeneratedFieldsTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testGeneratedFields(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures25'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures25'], 'exclude' => ['PostgreSQL'], ])); @@ -32,14 +36,11 @@ public function testGeneratedFields(ReaderInterface $reader): void new Entities(new TokenizerEntityLocator($locator, $reader), $reader), ]); - $this->assertSame( - [ - 'id' => GeneratedField::ON_INSERT, - 'createdAt' => GeneratedField::BEFORE_INSERT, - 'createdAtGeneratedByDatabase' => GeneratedField::ON_INSERT, - 'updatedAt' => GeneratedField::BEFORE_INSERT | GeneratedField::BEFORE_UPDATE, - ], - $schema['withGeneratedFields'][SchemaInterface::GENERATED_FIELDS], - ); + Assert::same($schema['withGeneratedFields'][SchemaInterface::GENERATED_FIELDS], [ + 'id' => GeneratedField::ON_INSERT, + 'createdAt' => GeneratedField::BEFORE_INSERT, + 'createdAtGeneratedByDatabase' => GeneratedField::ON_INSERT, + 'updatedAt' => GeneratedField::BEFORE_INSERT | GeneratedField::BEFORE_UPDATE, + ]); } } diff --git a/tests/Annotated/Functional/Driver/Common/GeneratorTestCase.php b/tests/Feature/Common/GeneratorTest.php similarity index 52% rename from tests/Annotated/Functional/Driver/Common/GeneratorTestCase.php rename to tests/Feature/Common/GeneratorTest.php index 33b1cadb..fc1e4e1d 100644 --- a/tests/Annotated/Functional/Driver/Common/GeneratorTestCase.php +++ b/tests/Feature/Common/GeneratorTest.php @@ -2,12 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Complete; use Cycle\Annotated\Tests\Fixtures\Fixtures1\CompleteMapper; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Constrain\SomeConstrain; @@ -19,26 +20,30 @@ use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\AnnotationReader; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\Composite\MergeReader; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class GeneratorTestCase extends BaseTestCase +final class GeneratorTest extends BaseTestCase { + #[Test] public function testCreateEntitiesWithNullReader(): void { $r = new Registry($this->dbal); (new Entities(new TokenizerEntityLocator($this->locator)))->run($r); - $this->assertTrue($r->hasEntity(Simple::class)); - $this->assertTrue($r->hasEntity(WithTable::class)); - $this->assertTrue($r->hasEntity(Complete::class)); + Assert::true($r->hasEntity(Simple::class)); + Assert::true($r->hasEntity(WithTable::class)); + Assert::true($r->hasEntity(Complete::class)); } + #[Test] public function testCreateGeneratorsWithDoctrineAnnotationReader(): void { $reader = new DoctrineAnnotationReader(); @@ -51,26 +56,27 @@ public function testCreateGeneratorsWithDoctrineAnnotationReader(): void (new SyncTables())->run($r); // Entities - $this->assertTrue($r->hasEntity(Simple::class)); - $this->assertTrue($r->hasEntity(WithTable::class)); - $this->assertTrue($r->hasEntity(Complete::class)); + Assert::true($r->hasEntity(Simple::class)); + Assert::true($r->hasEntity(WithTable::class)); + Assert::true($r->hasEntity(Complete::class)); // MergeColumns $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertTrue($schema->hasColumn('name')); - $this->assertSame('string', $schema->column('status')->getType()); + Assert::true($schema->hasColumn('name')); + Assert::same($schema->column('status')->getType(), 'string'); // MergeIndexes - $this->assertTrue($schema->hasIndex(['name'])); - $this->assertTrue($schema->index(['name'])->isUnique()); - $this->assertSame('name_index', $schema->index(['name'])->getName()); + Assert::true($schema->hasIndex(['name'])); + Assert::true($schema->index(['name'])->isUnique()); + Assert::same($schema->index(['name'])->getName(), 'name_index'); } + #[Test] public function testCreateGeneratorsWithCustomMergeReader(): void { $reader = new MergeReader([new AnnotationReader(), new AttributeReader()]); $r = new Registry($this->dbal); $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures10'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures10'], 'exclude' => [], ])); $locator = $tokenizer->classLocator(); @@ -82,69 +88,69 @@ public function testCreateGeneratorsWithCustomMergeReader(): void (new SyncTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('MergedMeta'))); + Assert::true($r->hasTable($r->getEntity('MergedMeta'))); $schema = $r->getTableSchema($r->getEntity('MergedMeta')); - $this->assertTrue($schema->hasColumn('name')); - $this->assertTrue($schema->hasIndex(['name', 'id DESC'])); + Assert::true($schema->hasColumn('name')); + Assert::true($schema->hasIndex(['name', 'id DESC'])); } #[DataProvider('allReadersProvider')] + #[Test] public function testLocateAll(ReaderInterface $reader): void { $r = new Registry($this->dbal); (new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader))->run($r); - $this->assertTrue($r->hasEntity(Simple::class)); - $this->assertTrue($r->hasEntity(WithTable::class)); - $this->assertTrue($r->hasEntity(Complete::class)); + Assert::true($r->hasEntity(Simple::class)); + Assert::true($r->hasEntity(WithTable::class)); + Assert::true($r->hasEntity(Complete::class)); } #[DataProvider('allReadersProvider')] + #[Test] public function testSimpleSchema(ReaderInterface $reader): void { $r = new Registry($this->dbal); (new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader))->run($r); - $this->assertTrue($r->hasEntity(Simple::class)); - $this->assertTrue($r->hasEntity('simple')); + Assert::true($r->hasEntity(Simple::class)); + Assert::true($r->hasEntity('simple')); - $this->assertSame(null, $r->getEntity('simple')->getMapper()); - $this->assertSame(null, $r->getEntity('simple')->getRepository()); + Assert::same($r->getEntity('simple')->getMapper(), null); + Assert::same($r->getEntity('simple')->getRepository(), null); - $this->assertTrue($r->hasTable($r->getEntity('simple'))); - $this->assertSame('default', $r->getDatabase($r->getEntity('simple'))); - $this->assertSame('simples', $r->getTable($r->getEntity('simple'))); + Assert::true($r->hasTable($r->getEntity('simple'))); + Assert::same($r->getDatabase($r->getEntity('simple')), 'default'); + Assert::same($r->getTable($r->getEntity('simple')), 'simples'); - $this->assertTrue($r->getEntity('simple')->getFields()->has('id')); - $this->assertSame('id', $r->getEntity('simple')->getFields()->get('id')->getColumn()); + Assert::true($r->getEntity('simple')->getFields()->has('id')); + Assert::same($r->getEntity('simple')->getFields()->get('id')->getColumn(), 'id'); } #[DataProvider('allReadersProvider')] + #[Test] public function testCompleteSchema(ReaderInterface $reader): void { $r = new Registry($this->dbal); (new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader))->run($r); - $this->assertTrue($r->hasEntity(Complete::class)); - $this->assertTrue($r->hasEntity('eComplete')); + Assert::true($r->hasEntity(Complete::class)); + Assert::true($r->hasEntity('eComplete')); - $this->assertSame(CompleteMapper::class, $r->getEntity('eComplete')->getMapper()); - $this->assertSame(CompleteRepository::class, $r->getEntity('eComplete')->getRepository()); - $this->assertSame(TestSource::class, $r->getEntity('eComplete')->getSource()); - $this->assertSame(SomeConstrain::class, $r->getEntity('eComplete')->getScope()); + Assert::same($r->getEntity('eComplete')->getMapper(), CompleteMapper::class); + Assert::same($r->getEntity('eComplete')->getRepository(), CompleteRepository::class); + Assert::same($r->getEntity('eComplete')->getSource(), TestSource::class); + Assert::same($r->getEntity('eComplete')->getScope(), SomeConstrain::class); - $this->assertTrue($r->hasTable($r->getEntity('eComplete'))); - $this->assertSame('secondary', $r->getDatabase($r->getEntity('eComplete'))); - $this->assertSame('complete_data', $r->getTable($r->getEntity('eComplete'))); + Assert::true($r->hasTable($r->getEntity('eComplete'))); + Assert::same($r->getDatabase($r->getEntity('eComplete')), 'secondary'); + Assert::same($r->getTable($r->getEntity('eComplete')), 'complete_data'); - $this->assertTrue($r->getEntity('eComplete')->getFields()->has('id')); - $this->assertTrue($r->getEntity('eComplete')->getFields()->has('name')); + Assert::true($r->getEntity('eComplete')->getFields()->has('id')); + Assert::true($r->getEntity('eComplete')->getFields()->has('name')); - $this->assertSame( - 'username', - $r->getEntity('eComplete')->getFields()->get('name')->getColumn(), - ); + Assert::same($r->getEntity('eComplete')->getFields()->get('name')->getColumn(), 'username'); - $this->assertFalse($r->getEntity('eComplete')->getFields()->has('ignored')); + Assert::false($r->getEntity('eComplete')->getFields()->has('ignored')); } } diff --git a/tests/Annotated/Functional/Driver/Common/Inheritance/JoinedTableTestCase.php b/tests/Feature/Common/Inheritance/JoinedTableTest.php similarity index 67% rename from tests/Annotated/Functional/Driver/Common/Inheritance/JoinedTableTestCase.php rename to tests/Feature/Common/Inheritance/JoinedTableTest.php index 831c9c00..49c8b301 100644 --- a/tests/Annotated/Functional/Driver/Common/Inheritance/JoinedTableTestCase.php +++ b/tests/Feature/Common/Inheritance/JoinedTableTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Inheritance; +namespace Cycle\Annotated\Tests\Feature\Common\Inheritance; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -11,9 +11,8 @@ use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; use Cycle\Annotated\TableInheritance; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures16\Executive; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; -use Cycle\Annotated\Tests\Traits\TableTrait; use Cycle\Database\Schema\AbstractForeignKey; use Cycle\Database\Schema\AbstractIndex; use Cycle\ORM\EntityManager; @@ -27,16 +26,18 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Lifecycle\BeforeTest; +use Testo\Test; -abstract class JoinedTableTestCase extends BaseTestCase +final class JoinedTableTest extends BaseTestCase { - use TableTrait; - #[DataProvider('allReadersProvider')] + #[Test] public function testTableInheritance(ReaderInterface $reader): void { $this->orm = $this->orm->with(new Schema($this->compile($reader))); @@ -57,16 +58,17 @@ public function testTableInheritance(ReaderInterface $reader): void $this->orm->getHeap()->clean(); $loadedExecutive = $this->orm->getRepository(Executive::class)->findByPK($executive->getFooId()); - $this->assertInstanceOf(Executive::class, $loadedExecutive); - $this->assertSame('executive', $loadedExecutive->getName()); - $this->assertSame(50000, $loadedExecutive->getSalary()); - $this->assertSame('secret', $loadedExecutive->hidden); - $this->assertSame(15000, $loadedExecutive->bonus); - $this->assertSame('executive', $loadedExecutive->getType()); - $this->assertSame('value', $loadedExecutive->proxyFieldWithAnnotation); + Assert::instanceOf($loadedExecutive, Executive::class); + Assert::same($loadedExecutive->getName(), 'executive'); + Assert::same($loadedExecutive->getSalary(), 50000); + Assert::same($loadedExecutive->hidden, 'secret'); + Assert::same($loadedExecutive->bonus, 15000); + Assert::same($loadedExecutive->getType(), 'executive'); + Assert::same($loadedExecutive->proxyFieldWithAnnotation, 'value'); } #[DataProvider('allReadersProvider')] + #[Test] public function testAddForeignKeys(ReaderInterface $reader): void { $this->orm = $this->orm->with(new Schema($this->compile($reader))); @@ -77,36 +79,38 @@ public function testAddForeignKeys(ReaderInterface $reader): void $externalSuppliersFk = $db->table('external_suppliers')->getForeignKeys(); // simple case. Supplier -> Person - $this->assertCount(1, $suppliersFk); - $this->assertInstanceOf(AbstractForeignKey::class, reset($suppliersFk)); - $this->assertSame('people', reset($suppliersFk)->getForeignTable()); - $this->assertSame(['id'], reset($suppliersFk)->getForeignKeys()); - $this->assertSame(['id'], reset($suppliersFk)->getColumns()); + Assert::count($suppliersFk, 1); + Assert::instanceOf(reset($suppliersFk), AbstractForeignKey::class); + Assert::same(reset($suppliersFk)->getForeignTable(), 'people'); + Assert::same(reset($suppliersFk)->getForeignKeys(), ['id']); + Assert::same(reset($suppliersFk)->getColumns(), ['id']); // Executive -> Employee (STI) -> Person - $this->assertCount(1, $executivesFk); - $this->assertInstanceOf(AbstractForeignKey::class, reset($executivesFk)); - $this->assertSame('people', reset($executivesFk)->getForeignTable()); - $this->assertSame(['id'], reset($executivesFk)->getForeignKeys()); - $this->assertSame(['id'], reset($executivesFk)->getColumns()); + Assert::count($executivesFk, 1); + Assert::instanceOf(reset($executivesFk), AbstractForeignKey::class); + Assert::same(reset($executivesFk)->getForeignTable(), 'people'); + Assert::same(reset($executivesFk)->getForeignKeys(), ['id']); + Assert::same(reset($executivesFk)->getColumns(), ['id']); // ExternalSupplier -> Supplier (JTI) -> Person. With outerKey - $this->assertCount(1, $externalSuppliersFk); - $this->assertInstanceOf(AbstractForeignKey::class, reset($externalSuppliersFk)); - $this->assertSame('suppliers', reset($externalSuppliersFk)->getForeignTable()); - $this->assertSame(['custom_id'], reset($externalSuppliersFk)->getForeignKeys()); - $this->assertSame(['id'], reset($externalSuppliersFk)->getColumns()); + Assert::count($externalSuppliersFk, 1); + Assert::instanceOf(reset($externalSuppliersFk), AbstractForeignKey::class); + Assert::same(reset($externalSuppliersFk)->getForeignTable(), 'suppliers'); + Assert::same(reset($externalSuppliersFk)->getForeignKeys(), ['custom_id']); + Assert::same(reset($externalSuppliersFk)->getColumns(), ['id']); } #[DataProvider('allReadersProvider')] + #[Test] public function testNotAddForeignKey(ReaderInterface $reader): void { $this->orm = $this->orm->with(new Schema($this->compile($reader))); - $this->assertCount(0, $this->dbal->database()->table('buyers')->getForeignKeys()); + Assert::count($this->dbal->database()->table('buyers')->getForeignKeys(), 0); } #[DataProvider('allReadersProvider')] + #[Test] public function testAddIndex(ReaderInterface $reader): void { $this->orm = $this->orm->with(new Schema($this->compile($reader))); @@ -117,36 +121,36 @@ public function testAddIndex(ReaderInterface $reader): void $indexes = array_filter($indexes, fn(AbstractIndex $index) => $index->getColumns() !== ['id']); // one index added automatically, one added manual - $this->assertCount(2, $indexes); + Assert::count($indexes, 2); - $this->assertTrue($this->dbal->database()->table('suppliers')->hasIndex(['index_id'])); - $this->assertTrue($this->dbal->database()->table('suppliers')->hasIndex(['custom_id'])); + Assert::true($this->dbal->database()->table('suppliers')->hasIndex(['index_id'])); + Assert::true($this->dbal->database()->table('suppliers')->hasIndex(['custom_id'])); - $this->assertTrue(reset($indexes)->isUnique()); - $this->assertTrue(end($indexes)->isUnique()); + Assert::true(reset($indexes)->isUnique()); + Assert::true(end($indexes)->isUnique()); } #[DataProvider('allReadersProvider')] + #[Test] public function testJtiParentColumns(ReaderInterface $reader): void { $schema = $this->compile($reader, 'Fixtures21'); - $this->assertNotEmpty($schema); + Assert::notBlank($schema); - $this->assertArrayHasKey(SchemaInterface::COLUMNS, $schema['person']); + Assert::array($schema['person'])->hasKeys(SchemaInterface::COLUMNS); // assert that parent doesn't have jti columns - $this->assertEquals([ + Assert::equals($schema['person'][SchemaInterface::COLUMNS], [ 'id' => 'id', 'name' => 'name', 'type' => 'type', - ], $schema['person'][SchemaInterface::COLUMNS]); + ]); } - public function setUp(): void + #[BeforeTest] + public function createTables(): void { - parent::setUp(); - $this->makeTable( table: 'people', columns: [ @@ -209,7 +213,7 @@ private function compile(ReaderInterface $reader, string $fixtures = 'Fixtures16 { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [sprintf(__DIR__ . '/../../../../Fixtures/%s', $fixtures)], + 'directories' => [sprintf(__DIR__ . '/../../../Fixtures/%s', $fixtures)], 'exclude' => [], ]), ); diff --git a/tests/Feature/Common/Inheritance/SingleTableTest.php b/tests/Feature/Common/Inheritance/SingleTableTest.php new file mode 100644 index 00000000..263d9bbd --- /dev/null +++ b/tests/Feature/Common/Inheritance/SingleTableTest.php @@ -0,0 +1,330 @@ + [__DIR__ . '/../../../Fixtures/Fixtures16'], + 'exclude' => [], + ]), + ); + + $locator = $tokenizer->classLocator(); + + $r = new Registry($this->dbal); + + $schema = (new Compiler())->compile($r, [ + new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), + new Entities(new TokenizerEntityLocator($locator, $reader), $reader), + new TableInheritance($reader), + new ResetTables(), + new MergeColumns($reader), + new GenerateRelations(), + new RenderTables(), + new RenderRelations(), + new MergeIndexes($reader), + new SyncTables(), + new GenerateTypecast(), + ]); + + $this->orm = $this->orm->with(new Schema($schema)); + + $t = new EntityManager($this->orm); + + $employee = new Employee(); + $employee->name = 'foo'; + $employee->salary = 12500; + $employee->bar = 'test'; + + $employee1 = new Employee(); + $employee1->name = 'bar'; + $employee1->salary = 23000; + + $person = new Person(); + $person->name = 'baz'; + + $customer = new Customer(); + $customer->name = 'baz'; + $customer->preferences = 'private'; + + $ceo = new Ceo(); + $ceo->name = 'ceo'; + $ceo->stocks = 1000; + $ceo->salary = 150000; + + $t->persist($employee); + $t->persist($employee1); + $t->persist($person); + $t->persist($customer); + $t->persist($ceo); + + $t->run(); + + $this->orm->getHeap()->clean(); + + Assert::notNull($person->getFooId()); + $loadedPerson = $this->orm->getRepository(Person::class)->findByPK($person->getFooId()); + Assert::instanceOf($loadedPerson, Person::class); + Assert::same($loadedPerson->name, 'baz'); + Assert::false(isset($loadedPerson->preferences)); + Assert::false(isset($loadedPerson->salary)); + + Assert::notNull($employee->getFooId()); + $loadedEmployee = $this->orm->getRepository(Person::class)->findByPK($employee->getFooId()); + Assert::instanceOf($loadedEmployee, Employee::class); + Assert::same($loadedEmployee->name, 'foo'); + Assert::same($loadedEmployee->salary, 12500); + Assert::same($loadedEmployee->bar, 'test'); + Assert::false(isset($loadedEmployee->preferences)); + + Assert::notNull($customer->getFooId()); + $loadedCustomer = $this->orm->getRepository(Person::class)->findByPK($customer->getFooId()); + Assert::instanceOf($loadedCustomer, Customer::class); + Assert::same($loadedCustomer->name, 'baz'); + Assert::same($loadedCustomer->preferences, 'private'); + Assert::false(isset($loadedCustomer->salary)); + + Assert::notNull($ceo->getFooId()); + $loadedCeo = $this->orm->getRepository(Ceo::class)->findByPK($ceo->getFooId()); + Assert::instanceOf($loadedCeo, Ceo::class); + Assert::same($loadedCeo->name, 'ceo'); + Assert::same($loadedCeo->salary, 150000); + Assert::same($loadedCeo->stocks, 1000); + } + + #[DataProvider('allReadersProvider')] + #[Test] + public function testTableInheritanceSchema(ReaderInterface $reader): void + { + $tokenizer = new Tokenizer( + new TokenizerConfig([ + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures20'], + 'exclude' => [], + ]), + ); + + $locator = $tokenizer->classLocator(); + + $r = new Registry($this->dbal); + + $schema = (new Compiler())->compile($r, [ + new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), + new Entities(new TokenizerEntityLocator($locator, $reader), $reader), + new TableInheritance($reader), + new ResetTables(), + new MergeColumns($reader), + new GenerateRelations(), + new RenderTables(), + new RenderRelations(), + new MergeIndexes($reader), + new GenerateTypecast(), + ]); + + Assert::notBlank($schema); + + Assert::array($schema['person'])->hasKeys(SchemaInterface::CHILDREN); + Assert::array($schema['person'])->hasKeys(SchemaInterface::DISCRIMINATOR); + Assert::same($schema['person'][SchemaInterface::DISCRIMINATOR], 'type'); + + Assert::array($schema['buyer'])->hasKeys(SchemaInterface::PARENT); + Assert::array($schema['buyer'])->hasKeys(SchemaInterface::PARENT_KEY); + } + + #[DataProvider('columnDeclarationWithReadersDataProvider')] + #[Test] + public function testSingleTableInheritanceWithDifferentColumnDeclaration( + string $directory, + string $namespace, + ReaderInterface $reader, + ): void { + $tokenizer = new Tokenizer( + new TokenizerConfig([ + 'directories' => [$directory], + 'exclude' => [], + ]), + ); + + $locator = $tokenizer->classLocator(); + + $r = new Registry($this->dbal); + + $schema = (new Compiler())->compile($r, [ + new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), + new Entities(new TokenizerEntityLocator($locator, $reader), $reader), + new MergeColumns($reader), + new TableInheritance($reader), + new ResetTables(), + new GenerateRelations(), + new RenderTables(), + new RenderRelations(), + new MergeIndexes($reader), + new GenerateTypecast(), + ]); + + Assert::notBlank($schema); + Assert::same($schema['baseEvent'][SchemaInterface::ENTITY], \sprintf( + 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\BaseEvent', + $namespace, + )); + Assert::same($schema['baseEvent'][SchemaInterface::MAPPER], Mapper::class); + Assert::same($schema['baseEvent'][SchemaInterface::SOURCE], Source::class); + Assert::same($schema['baseEvent'][SchemaInterface::REPOSITORY], Repository::class); + Assert::same($schema['baseEvent'][SchemaInterface::DATABASE], 'default'); + Assert::same($schema['baseEvent'][SchemaInterface::TABLE], 'base_events'); + Assert::same($schema['baseEvent'][SchemaInterface::PRIMARY_KEY], ['id']); + Assert::same($schema['baseEvent'][SchemaInterface::FIND_BY_KEYS], ['id']); + Assert::count($schema['baseEvent'][SchemaInterface::COLUMNS], 4); + Assert::same($schema['baseEvent'][SchemaInterface::COLUMNS]['id'], 'id'); + Assert::same($schema['baseEvent'][SchemaInterface::COLUMNS]['action'], 'action'); + Assert::same($schema['baseEvent'][SchemaInterface::COLUMNS]['object_id'], 'object_id'); + Assert::same($schema['baseEvent'][SchemaInterface::COLUMNS]['object_type'], 'object_type'); + Assert::same($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::TYPE], Relation::BELONGS_TO_MORPHED); + Assert::same($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::TARGET], \sprintf('Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\EventEmitterInterface', $namespace)); + Assert::same($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::LOAD], Relation::LOAD_PROMISE); + Assert::true($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::CASCADE]); + Assert::true($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::NULLABLE]); + Assert::same($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::OUTER_KEY], ['id']); + Assert::same($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::INNER_KEY], 'object_id'); + Assert::same($schema['baseEvent'][SchemaInterface::RELATIONS]['object'][Relation::SCHEMA][Relation::MORPH_KEY], 'object_type'); + Assert::count($schema['baseEvent'][SchemaInterface::CHILDREN], 2); + Assert::same($schema['baseEvent'][SchemaInterface::CHILDREN]['comment.created'], \sprintf('Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentCreated', $namespace)); + Assert::same($schema['baseEvent'][SchemaInterface::CHILDREN]['comment.updated'], \sprintf('Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentUpdated', $namespace)); + Assert::null($schema['baseEvent'][SchemaInterface::SCOPE]); + Assert::same($schema['baseEvent'][SchemaInterface::TYPECAST]['id'], 'int'); + Assert::same($schema['baseEvent'][SchemaInterface::TYPECAST]['object_id'], 'int'); + Assert::same($schema['baseEvent'][SchemaInterface::SCHEMA], []); + Assert::same($schema['baseEvent'][SchemaInterface::DISCRIMINATOR], 'action'); + Assert::null($schema['baseEvent'][SchemaInterface::TYPECAST_HANDLER]); + Assert::same($schema['comment'], [ + SchemaInterface::ENTITY => \sprintf( + 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\Comment', + $namespace, + ), + SchemaInterface::MAPPER => Mapper::class, + SchemaInterface::SOURCE => Source::class, + SchemaInterface::REPOSITORY => Repository::class, + SchemaInterface::DATABASE => 'default', + SchemaInterface::TABLE => 'comments', + SchemaInterface::PRIMARY_KEY => [ + 'id', + ], + SchemaInterface::FIND_BY_KEYS => [ + 'id', + ], + SchemaInterface::COLUMNS => [ + 'id' => 'id', + 'body' => 'body', + ], + SchemaInterface::RELATIONS => [], + SchemaInterface::SCOPE => null, + SchemaInterface::TYPECAST => [ + 'id' => 'int', + 'body' => 'string', + ], + SchemaInterface::SCHEMA => [], + SchemaInterface::TYPECAST_HANDLER => null, + SchemaInterface::GENERATED_FIELDS => [ + 'id' => GeneratedField::ON_INSERT, + ], + ]); + Assert::same($schema['commentCreated'], [ + SchemaInterface::ENTITY => \sprintf( + 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentCreated', + $namespace, + ), + ]); + Assert::same($schema['commentUpdated'], [ + SchemaInterface::ENTITY => \sprintf( + 'Cycle\Annotated\Tests\Fixtures\Fixtures23\%s\CommentUpdated', + $namespace, + ), + ]); + } + + #[BeforeTest] + public function createTables(): void + { + $this->makeTable('people', [ + 'id' => 'primary', + 'type' => 'string', + 'name' => 'string', + 'salary' => 'float', + 'preferences' => 'string', + 'bar' => 'string', + 'stocks' => 'int', + ]); + } +} diff --git a/tests/Annotated/Functional/Driver/Common/InheritanceTestCase.php b/tests/Feature/Common/InheritanceTest.php similarity index 54% rename from tests/Annotated/Functional/Driver/Common/InheritanceTestCase.php rename to tests/Feature/Common/InheritanceTest.php index 27889034..43b18434 100644 --- a/tests/Annotated/Functional/Driver/Common/InheritanceTestCase.php +++ b/tests/Feature/Common/InheritanceTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -11,6 +11,7 @@ use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; use Cycle\Annotated\TableInheritance; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures16\Ceo; use Cycle\Annotated\Tests\Fixtures\Fixtures16\Customer; use Cycle\Annotated\Tests\Fixtures\Fixtures16\Employee; @@ -43,21 +44,24 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; +use Cycle\Testing\ORM\Schema\ClassList; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\ReaderInterface; -use Spiral\Tokenizer\ClassesInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class InheritanceTestCase extends BaseTestCase +final class InheritanceTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testTableInheritance(ReaderInterface $reader): void { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures16'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures16'], 'exclude' => [__DIR__ . '/Fixtures16/CatWithoutParent.php'], ]), ); @@ -88,17 +92,17 @@ public function testTableInheritance(ReaderInterface $reader): void // Beaver - Separate table // Tool - $this->assertArrayHasKey('tool', $schema); + Assert::array($schema)->hasKeys('tool'); // Person - $this->assertCount(3, $schema['person'][SchemaInterface::CHILDREN]); - $this->assertEquals([ + Assert::count($schema['person'][SchemaInterface::CHILDREN], 3); + Assert::equals($schema['person'][SchemaInterface::CHILDREN], [ 'employee' => Employee::class, 'foo_customer' => Customer::class, 'ceo' => Ceo::class, - ], $schema['person'][SchemaInterface::CHILDREN]); - $this->assertSame('type', $schema['person'][SchemaInterface::DISCRIMINATOR]); - $this->assertEquals([ + ]); + Assert::same($schema['person'][SchemaInterface::DISCRIMINATOR], 'type'); + Assert::equals($schema['person'][SchemaInterface::COLUMNS], [ 'foo_id' => 'id', 'name' => 'name', 'type' => 'type', @@ -109,85 +113,75 @@ public function testTableInheritance(ReaderInterface $reader): void 'stocks' => 'stocks', 'tool_id' => 'tool_id', // 'teethAmount' => 'teeth_amount', // Not child - ], $schema['person'][SchemaInterface::COLUMNS]); - $this->assertEmpty($schema['person'][SchemaInterface::PARENT] ?? null); - $this->assertEmpty($schema['person'][SchemaInterface::PARENT_KEY] ?? null); - $this->assertSame('people', $schema['person'][SchemaInterface::TABLE]); - $this->assertCount(1, $schema['person'][SchemaInterface::RELATIONS]); + ]); + Assert::blank($schema['person'][SchemaInterface::PARENT] ?? null); + Assert::blank($schema['person'][SchemaInterface::PARENT_KEY] ?? null); + Assert::same($schema['person'][SchemaInterface::TABLE], 'people'); + Assert::count($schema['person'][SchemaInterface::RELATIONS], 1); // Employee - $this->assertArrayHasKey('employee', $schema); - $this->assertCount(1, $schema['employee']); - $this->assertSame(Employee::class, $schema['employee'][SchemaInterface::ENTITY]); - $this->assertNull($schema['employee'][SchemaInterface::TABLE] ?? null); - $this->assertCount(0, $schema['employee'][SchemaInterface::RELATIONS] ?? []); + Assert::array($schema)->hasKeys('employee'); + Assert::count($schema['employee'], 1); + Assert::same($schema['employee'][SchemaInterface::ENTITY], Employee::class); + Assert::null($schema['employee'][SchemaInterface::TABLE] ?? null); + Assert::count($schema['employee'][SchemaInterface::RELATIONS] ?? [], 0); // Customer - $this->assertArrayHasKey('customer', $schema); - $this->assertCount(1, $schema['customer']); - $this->assertSame(Customer::class, $schema['customer'][SchemaInterface::ENTITY]); - $this->assertNull($schema['customer'][SchemaInterface::TABLE] ?? null); - $this->assertCount(0, $schema['customer'][SchemaInterface::RELATIONS] ?? []); + Assert::array($schema)->hasKeys('customer'); + Assert::count($schema['customer'], 1); + Assert::same($schema['customer'][SchemaInterface::ENTITY], Customer::class); + Assert::null($schema['customer'][SchemaInterface::TABLE] ?? null); + Assert::count($schema['customer'][SchemaInterface::RELATIONS] ?? [], 0); // Executive - $this->assertSame('employee', $schema['executive'][SchemaInterface::PARENT]); - $this->assertSame('foo_id', $schema['executive'][SchemaInterface::PARENT_KEY]); - $this->assertSame('executives', $schema['executive'][SchemaInterface::TABLE]); - $this->assertEquals( - [ - 'bonus' => 'bonus', - 'proxyFieldWithAnnotation' => 'proxy', - 'foo_id' => 'id', - 'hidden' => 'hidden', - 'added_tool_id' => 'added_tool_id', - ], - $schema['executive'][SchemaInterface::COLUMNS], - ); - $this->assertCount(1, $schema['executive'][SchemaInterface::RELATIONS]); + Assert::same($schema['executive'][SchemaInterface::PARENT], 'employee'); + Assert::same($schema['executive'][SchemaInterface::PARENT_KEY], 'foo_id'); + Assert::same($schema['executive'][SchemaInterface::TABLE], 'executives'); + Assert::equals($schema['executive'][SchemaInterface::COLUMNS], [ + 'bonus' => 'bonus', + 'proxyFieldWithAnnotation' => 'proxy', + 'foo_id' => 'id', + 'hidden' => 'hidden', + 'added_tool_id' => 'added_tool_id', + ]); + Assert::count($schema['executive'][SchemaInterface::RELATIONS], 1); // Executive2 - $this->assertSame('executive', $schema['executive2'][SchemaInterface::PARENT]); - $this->assertSame('foo_id', $schema['executive2'][SchemaInterface::PARENT_KEY]); - $this->assertEquals(['foo_id' => 'id'], $schema['executive2'][SchemaInterface::COLUMNS]); - $this->assertCount(0, $schema['executive2'][SchemaInterface::RELATIONS]); + Assert::same($schema['executive2'][SchemaInterface::PARENT], 'executive'); + Assert::same($schema['executive2'][SchemaInterface::PARENT_KEY], 'foo_id'); + Assert::equals($schema['executive2'][SchemaInterface::COLUMNS], ['foo_id' => 'id']); + Assert::count($schema['executive2'][SchemaInterface::RELATIONS], 0); // Ceo - $this->assertArrayHasKey('ceo', $schema); - $this->assertCount(1, $schema['ceo']); - $this->assertSame(Ceo::class, $schema['ceo'][SchemaInterface::ENTITY]); - $this->assertNull($schema['ceo'][SchemaInterface::TABLE] ?? null); - $this->assertCount(0, $schema['ceo'][SchemaInterface::RELATIONS] ?? []); + Assert::array($schema)->hasKeys('ceo'); + Assert::count($schema['ceo'], 1); + Assert::same($schema['ceo'][SchemaInterface::ENTITY], Ceo::class); + Assert::null($schema['ceo'][SchemaInterface::TABLE] ?? null); + Assert::count($schema['ceo'][SchemaInterface::RELATIONS] ?? [], 0); // Beaver - $this->assertEmpty($schema['beaver'][SchemaInterface::DISCRIMINATOR] ?? null); - $this->assertEmpty($schema['beaver'][SchemaInterface::PARENT] ?? null); - $this->assertEmpty($schema['beaver'][SchemaInterface::PARENT_KEY] ?? null); - $this->assertEmpty($schema['beaver'][SchemaInterface::CHILDREN] ?? null); - $this->assertSame('beavers', $schema['beaver'][SchemaInterface::TABLE]); - $this->assertEquals([ + Assert::blank($schema['beaver'][SchemaInterface::DISCRIMINATOR] ?? null); + Assert::blank($schema['beaver'][SchemaInterface::PARENT] ?? null); + Assert::blank($schema['beaver'][SchemaInterface::PARENT_KEY] ?? null); + Assert::blank($schema['beaver'][SchemaInterface::CHILDREN] ?? null); + Assert::same($schema['beaver'][SchemaInterface::TABLE], 'beavers'); + Assert::equals($schema['beaver'][SchemaInterface::COLUMNS], [ 'teethAmount' => 'teeth_amount', 'foo_id' => 'id', 'name' => 'name', 'type' => 'type', 'hidden' => 'hidden', 'tool_id' => 'tool_id', - ], $schema['beaver'][SchemaInterface::COLUMNS]); - $this->assertCount(1, $schema['beaver'][SchemaInterface::RELATIONS] ?? []); + ]); + Assert::count($schema['beaver'][SchemaInterface::RELATIONS] ?? [], 1); } + #[Test] public function testTableInheritanceWithIncorrectClassesOrder(): void { $r = new Registry($this->dbal); $reader = new AttributeReader(); - $locator = $this->createMock(ClassesInterface::class); - $locator - ->method('getClasses') - ->willReturn([ - new \ReflectionClass(Employee::class), - new \ReflectionClass(Executive::class), - new \ReflectionClass(Person::class), - new \ReflectionClass(Tool::class), - ]); + $locator = new ClassList(Employee::class, Executive::class, Person::class, Tool::class); $schema = (new Compiler())->compile($r, [ new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), @@ -203,34 +197,37 @@ public function testTableInheritanceWithIncorrectClassesOrder(): void new GenerateTypecast(), ]); - $this->assertSame('executives', $schema['executive'][SchemaInterface::TABLE]); - $this->assertNull($schema['employee'][SchemaInterface::TABLE] ?? null); - $this->assertSame('people', $schema['person'][SchemaInterface::TABLE]); + Assert::same($schema['executive'][SchemaInterface::TABLE], 'executives'); + Assert::null($schema['employee'][SchemaInterface::TABLE] ?? null); + Assert::same($schema['person'][SchemaInterface::TABLE], 'people'); } + #[Test] public function testJtiChildDoesNotInheritBelongsToColumn(): void { $schema = $this->compileWithClasses([BtTarget::class, BtParent::class, BtJoined::class]); // BtParent owns the BelongsTo + its FK column - $this->assertArrayHasKey('target_id', $schema['btParent'][SchemaInterface::COLUMNS]); - $this->assertCount(1, $schema['btParent'][SchemaInterface::RELATIONS]); + Assert::array($schema['btParent'][SchemaInterface::COLUMNS])->hasKeys('target_id'); + Assert::count($schema['btParent'][SchemaInterface::RELATIONS], 1); // JTI child must not duplicate the BelongsTo FK column nor inherit the relation - $this->assertArrayNotHasKey('target_id', $schema['btJoined'][SchemaInterface::COLUMNS]); - $this->assertCount(0, $schema['btJoined'][SchemaInterface::RELATIONS] ?? []); + Assert::array($schema['btJoined'][SchemaInterface::COLUMNS])->doesNotHaveKeys('target_id'); + Assert::count($schema['btJoined'][SchemaInterface::RELATIONS] ?? [], 0); } + #[Test] public function testStiChildOwnRelationMergesIntoParent(): void { $schema = $this->compileWithClasses([StTarget::class, StParent::class, StChild::class]); // Relation declared on the STI child must end up on the parent after merge - $this->assertArrayHasKey('target_id', $schema['stParent'][SchemaInterface::COLUMNS]); - $this->assertCount(1, $schema['stParent'][SchemaInterface::RELATIONS]); - $this->assertArrayHasKey('target', $schema['stParent'][SchemaInterface::RELATIONS]); + Assert::array($schema['stParent'][SchemaInterface::COLUMNS])->hasKeys('target_id'); + Assert::count($schema['stParent'][SchemaInterface::RELATIONS], 1); + Assert::array($schema['stParent'][SchemaInterface::RELATIONS])->hasKeys('target'); } + #[Test] public function testSeparateEntityExtendingStiChildKeepsInheritedRelation(): void { $schema = $this->compileWithClasses([ @@ -241,27 +238,29 @@ public function testSeparateEntityExtendingStiChildKeepsInheritedRelation(): voi ]); // Separate entity (no Inheritance attr) extending an STI child must keep ancestor relations - $this->assertEmpty($schema['soSeparate'][SchemaInterface::PARENT] ?? null); - $this->assertNotNull($schema['soSeparate'][SchemaInterface::TABLE] ?? null); - $this->assertArrayHasKey('target_id', $schema['soSeparate'][SchemaInterface::COLUMNS]); - $this->assertArrayHasKey('extra', $schema['soSeparate'][SchemaInterface::COLUMNS]); - $this->assertCount(1, $schema['soSeparate'][SchemaInterface::RELATIONS] ?? []); - $this->assertArrayHasKey('target', $schema['soSeparate'][SchemaInterface::RELATIONS]); + Assert::blank($schema['soSeparate'][SchemaInterface::PARENT] ?? null); + Assert::notNull($schema['soSeparate'][SchemaInterface::TABLE] ?? null); + Assert::array($schema['soSeparate'][SchemaInterface::COLUMNS])->hasKeys('target_id'); + Assert::array($schema['soSeparate'][SchemaInterface::COLUMNS])->hasKeys('extra'); + Assert::count($schema['soSeparate'][SchemaInterface::RELATIONS] ?? [], 1); + Assert::array($schema['soSeparate'][SchemaInterface::RELATIONS])->hasKeys('target'); } + #[Test] public function testJtiChildDoesNotInheritRelationFromTrait(): void { $schema = $this->compileWithClasses([TrTarget::class, TrParent::class, TrJti::class]); // Trait-declared relation belongs to the entity that uses the trait - $this->assertArrayHasKey('target_id', $schema['trParent'][SchemaInterface::COLUMNS]); - $this->assertCount(1, $schema['trParent'][SchemaInterface::RELATIONS]); + Assert::array($schema['trParent'][SchemaInterface::COLUMNS])->hasKeys('target_id'); + Assert::count($schema['trParent'][SchemaInterface::RELATIONS], 1); // JTI child must not duplicate the trait's relation columns - $this->assertArrayNotHasKey('target_id', $schema['trJti'][SchemaInterface::COLUMNS]); - $this->assertCount(0, $schema['trJti'][SchemaInterface::RELATIONS] ?? []); + Assert::array($schema['trJti'][SchemaInterface::COLUMNS])->doesNotHaveKeys('target_id'); + Assert::count($schema['trJti'][SchemaInterface::RELATIONS] ?? [], 0); } + #[Test] public function testJtiGrandchildDoesNotInheritMidLevelRelation(): void { $schema = $this->compileWithClasses([ @@ -272,12 +271,12 @@ public function testJtiGrandchildDoesNotInheritMidLevelRelation(): void ]); // Relation declared on the JTI middle entity stays on the middle table - $this->assertArrayHasKey('target_id', $schema['jgMid'][SchemaInterface::COLUMNS]); - $this->assertCount(1, $schema['jgMid'][SchemaInterface::RELATIONS]); + Assert::array($schema['jgMid'][SchemaInterface::COLUMNS])->hasKeys('target_id'); + Assert::count($schema['jgMid'][SchemaInterface::RELATIONS], 1); // JTI grandchild must not duplicate the middle entity's relation column - $this->assertArrayNotHasKey('target_id', $schema['jgLeaf'][SchemaInterface::COLUMNS]); - $this->assertCount(0, $schema['jgLeaf'][SchemaInterface::RELATIONS] ?? []); + Assert::array($schema['jgLeaf'][SchemaInterface::COLUMNS])->doesNotHaveKeys('target_id'); + Assert::count($schema['jgLeaf'][SchemaInterface::RELATIONS] ?? [], 0); } /** @@ -286,10 +285,7 @@ public function testJtiGrandchildDoesNotInheritMidLevelRelation(): void private function compileWithClasses(array $classes): array { $reader = new AttributeReader(); - $locator = $this->createMock(ClassesInterface::class); - $locator->method('getClasses')->willReturn( - \array_map(static fn(string $c) => new \ReflectionClass($c), $classes), - ); + $locator = new ClassList(...$classes); return (new Compiler())->compile(new Registry($this->dbal), [ new Embeddings(new TokenizerEmbeddingLocator($locator, $reader), $reader), diff --git a/tests/Annotated/Functional/Driver/Common/InvalidTestCase.php b/tests/Feature/Common/InvalidTest.php similarity index 83% rename from tests/Annotated/Functional/Driver/Common/InvalidTestCase.php rename to tests/Feature/Common/InvalidTest.php index a9d0c31b..757cc5d0 100644 --- a/tests/Annotated/Functional/Driver/Common/InvalidTestCase.php +++ b/tests/Feature/Common/InvalidTest.php @@ -2,13 +2,14 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Entities; use Cycle\Annotated\Exception\AnnotationException; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Schema\Compiler; use Cycle\Schema\Exception\RelationException; use Cycle\Schema\Generator\GenerateRelations; @@ -19,19 +20,22 @@ use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Generator\ValidateEntities; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\AnnotationReader; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Data\DataProvider; +use Testo\Expect; +use Testo\Test; -abstract class InvalidTestCase extends BaseTestCase +final class InvalidTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testInvalidRelation(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures3'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures3'], 'exclude' => [], ])); @@ -39,7 +43,7 @@ public function testInvalidRelation(ReaderInterface $reader): void $r = new Registry($this->dbal); - $this->expectException(RelationException::class); + Expect::exception(RelationException::class); (new Compiler())->compile($r, [ new Entities(new TokenizerEntityLocator($locator, $reader), $reader), @@ -56,17 +60,17 @@ public function testInvalidRelation(ReaderInterface $reader): void } #[DataProvider('allReadersProvider')] + #[Test] public function testNotDefinedColumnTypeShouldThrowAnException(ReaderInterface $reader): void { $message = $reader instanceof AnnotationReader ? 'Too few arguments to function Cycle\Annotated\Annotation\Column::__construct(), 0 passed' : 'Some of required arguments [`type`] is missed on `Cycle\Annotated\Tests\Fixtures\Fixtures4\User.id.`'; - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage($message); + Expect::exception(AnnotationException::class)->withMessageContaining($message); $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures4'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures4'], 'exclude' => [], ])); diff --git a/tests/Annotated/Functional/Driver/Common/Relation/BelongsToTestCase.php b/tests/Feature/Common/Relation/BelongsToTest.php similarity index 68% rename from tests/Annotated/Functional/Driver/Common/Relation/BelongsToTestCase.php rename to tests/Feature/Common/Relation/BelongsToTest.php index 3d2ce88a..8ddf06a5 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/BelongsToTestCase.php +++ b/tests/Feature/Common/Relation/BelongsToTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\Schema\Compiler; @@ -19,12 +19,15 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class BelongsToTestCase extends BaseTestCase +final class BelongsToTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -41,8 +44,8 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('parent', $schema['eComplete'][Schema::RELATIONS]); - $this->assertSame(Relation::BELONGS_TO, $schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TYPE]); - $this->assertSame('simple', $schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TARGET]); + Assert::array($schema['eComplete'][Schema::RELATIONS])->hasKeys('parent'); + Assert::same($schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TYPE], Relation::BELONGS_TO); + Assert::same($schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TARGET], 'simple'); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/CompositeKeysTestCase.php b/tests/Feature/Common/Relation/CompositeKeysTest.php similarity index 80% rename from tests/Annotated/Functional/Driver/Common/Relation/CompositeKeysTestCase.php rename to tests/Feature/Common/Relation/CompositeKeysTest.php index 4990106d..d2d42643 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/CompositeKeysTestCase.php +++ b/tests/Feature/Common/Relation/CompositeKeysTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -10,7 +10,7 @@ use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Schema\Compiler; use Cycle\Schema\Generator\GenerateRelations; use Cycle\Schema\Generator\GenerateTypecast; @@ -19,18 +19,21 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class CompositeKeysTestCase extends BaseTestCase +final class CompositeKeysTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelationToChild(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [dirname(__DIR__) . '/../../../Fixtures/Fixtures14'], + 'directories' => [dirname(__DIR__) . '/../../Fixtures/Fixtures14'], 'exclude' => [], ])); @@ -51,6 +54,6 @@ public function testRelationToChild(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertTrue(true, 'No exceptions thrown.'); + Assert::true(true, 'No exceptions thrown.'); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/EmbeddedTestCase.php b/tests/Feature/Common/Relation/EmbeddedTest.php similarity index 70% rename from tests/Annotated/Functional/Driver/Common/Relation/EmbeddedTestCase.php rename to tests/Feature/Common/Relation/EmbeddedTest.php index 2233756a..5cedd5d0 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/EmbeddedTestCase.php +++ b/tests/Feature/Common/Relation/EmbeddedTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -10,8 +10,8 @@ use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures26\CityTypecast; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\Schema\Compiler; @@ -22,18 +22,21 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class EmbeddedTestCase extends BaseTestCase +final class EmbeddedTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures6'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures6'], 'exclude' => [], ])); @@ -54,19 +57,20 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('address', $schema['user'][Schema::RELATIONS]); - $this->assertSame(Relation::EMBEDDED, $schema['user'][Schema::RELATIONS]['address'][Relation::TYPE]); + Assert::array($schema['user'][Schema::RELATIONS])->hasKeys('address'); + Assert::same($schema['user'][Schema::RELATIONS]['address'][Relation::TYPE], Relation::EMBEDDED); - $this->assertSame('user:address:address', $schema['user'][Schema::RELATIONS]['address'][Relation::TARGET]); - $this->assertSame(Relation::LOAD_EAGER, $schema['user'][Schema::RELATIONS]['address'][Relation::LOAD]); - $this->assertTrue($r->getTableSchema($r->getEntity('user'))->hasIndex(['address_zipcode'])); + Assert::same($schema['user'][Schema::RELATIONS]['address'][Relation::TARGET], 'user:address:address'); + Assert::same($schema['user'][Schema::RELATIONS]['address'][Relation::LOAD], Relation::LOAD_EAGER); + Assert::true($r->getTableSchema($r->getEntity('user'))->hasIndex(['address_zipcode'])); } #[DataProvider('allReadersProvider')] + #[Test] public function testRelationLazyLoad(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures7'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures7'], 'exclude' => [], ])); @@ -87,19 +91,20 @@ public function testRelationLazyLoad(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('address', $schema['user'][Schema::RELATIONS]); - $this->assertSame(Relation::EMBEDDED, $schema['user'][Schema::RELATIONS]['address'][Relation::TYPE]); + Assert::array($schema['user'][Schema::RELATIONS])->hasKeys('address'); + Assert::same($schema['user'][Schema::RELATIONS]['address'][Relation::TYPE], Relation::EMBEDDED); - $this->assertSame('user:address:address', $schema['user'][Schema::RELATIONS]['address'][Relation::TARGET]); - $this->assertSame(Relation::LOAD_PROMISE, $schema['user'][Schema::RELATIONS]['address'][Relation::LOAD]); - $this->assertTrue($r->getTableSchema($r->getEntity('user:address:address'))->hasIndex(['address_zipcode'])); + Assert::same($schema['user'][Schema::RELATIONS]['address'][Relation::TARGET], 'user:address:address'); + Assert::same($schema['user'][Schema::RELATIONS]['address'][Relation::LOAD], Relation::LOAD_PROMISE); + Assert::true($r->getTableSchema($r->getEntity('user:address:address'))->hasIndex(['address_zipcode'])); } #[DataProvider('allReadersProvider')] + #[Test] public function testEmbeddedPrefix(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures6'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures6'], 'exclude' => [], ])); @@ -135,15 +140,16 @@ public function testEmbeddedPrefix(ReaderInterface $reader): void 'id' => 'id', ]; - $this->assertSame($address, $schema['user:address:address'][Schema::COLUMNS]); - $this->assertSame($workAddress, $schema['user:address:workAddress'][Schema::COLUMNS]); + Assert::same($schema['user:address:address'][Schema::COLUMNS], $address); + Assert::same($schema['user:address:workAddress'][Schema::COLUMNS], $workAddress); } #[DataProvider('allReadersProvider')] + #[Test] public function testEmbeddedTypecast(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures26'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures26'], 'exclude' => [], ])); @@ -164,6 +170,6 @@ public function testEmbeddedTypecast(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertSame(CityTypecast::class, $schema['user:address:address'][Schema::TYPECAST_HANDLER][0]); + Assert::same($schema['user:address:address'][Schema::TYPECAST_HANDLER][0], CityTypecast::class); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/HasManyTestCase.php b/tests/Feature/Common/Relation/HasManyTest.php similarity index 63% rename from tests/Annotated/Functional/Driver/Common/Relation/HasManyTestCase.php rename to tests/Feature/Common/Relation/HasManyTest.php index c4db451b..e6c01d62 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/HasManyTestCase.php +++ b/tests/Feature/Common/Relation/HasManyTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\SchemaInterface; use Cycle\ORM\SchemaInterface as Schema; @@ -20,15 +20,18 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class HasManyTestCase extends BaseTestCase +final class HasManyTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -48,27 +51,19 @@ public function testRelation(ReaderInterface $reader): void ], ); - $this->assertArrayHasKey('many', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::HAS_MANY, $schema['simple'][Schema::RELATIONS]['many'][Relation::TYPE]); - $this->assertSame('withTable', $schema['simple'][Schema::RELATIONS]['many'][Relation::TARGET]); - $this->assertSame( - ['id' => ['>=' => 1]], - $schema['simple'][Schema::RELATIONS]['many'][Relation::SCHEMA][Relation::WHERE], - ); - $this->assertSame( - ['id' => 'DESC'], - $schema['simple'][Schema::RELATIONS]['many'][Relation::SCHEMA][Relation::ORDER_BY], - ); - $this->assertSame( - 'bar', - $schema['simple'][Schema::RELATIONS]['many'][Relation::SCHEMA][Relation::COLLECTION_TYPE], - ); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('many'); + Assert::same($schema['simple'][Schema::RELATIONS]['many'][Relation::TYPE], Relation::HAS_MANY); + Assert::same($schema['simple'][Schema::RELATIONS]['many'][Relation::TARGET], 'withTable'); + Assert::same($schema['simple'][Schema::RELATIONS]['many'][Relation::SCHEMA][Relation::WHERE], ['id' => ['>=' => 1]]); + Assert::same($schema['simple'][Schema::RELATIONS]['many'][Relation::SCHEMA][Relation::ORDER_BY], ['id' => 'DESC']); + Assert::same($schema['simple'][Schema::RELATIONS]['many'][Relation::SCHEMA][Relation::COLLECTION_TYPE], 'bar'); } + #[Test] public function testInnerOuterKeys(): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures18'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures18'], 'exclude' => [], ])); $reader = new AttributeReader(); @@ -101,17 +96,9 @@ public function testInnerOuterKeys(): void foreach ($checks as [$name, $innerKey, $outerKey]) { $relation = $schema['booking_reservation'][SchemaInterface::RELATIONS][$name]; - $this->assertSame(Relation::HAS_MANY, $relation[Relation::TYPE], "$name: relation type"); - $this->assertSame( - (array) $innerKey, - (array) $relation[Relation::SCHEMA][Relation::INNER_KEY], - "$name: Inner Key", - ); - $this->assertSame( - (array) $outerKey, - (array) $relation[Relation::SCHEMA][Relation::OUTER_KEY], - "$name: Outer Key", - ); + Assert::same($relation[Relation::TYPE], Relation::HAS_MANY, "$name: relation type"); + Assert::same((array) $relation[Relation::SCHEMA][Relation::INNER_KEY], (array) $innerKey, "$name: Inner Key"); + Assert::same((array) $relation[Relation::SCHEMA][Relation::OUTER_KEY], (array) $outerKey, "$name: Outer Key"); } } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/HasOneTestCase.php b/tests/Feature/Common/Relation/HasOneTest.php similarity index 66% rename from tests/Annotated/Functional/Driver/Common/Relation/HasOneTestCase.php rename to tests/Feature/Common/Relation/HasOneTest.php index 430d5db6..5ae98b24 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/HasOneTestCase.php +++ b/tests/Feature/Common/Relation/HasOneTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\SchemaInterface; use Cycle\Schema\Compiler; @@ -19,15 +19,18 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class HasOneTestCase extends BaseTestCase +final class HasOneTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -44,17 +47,18 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('one', $schema['simple'][SchemaInterface::RELATIONS]); - $this->assertSame(Relation::HAS_ONE, $schema['simple'][SchemaInterface::RELATIONS]['one'][Relation::TYPE]); - $this->assertSame('eComplete', $schema['simple'][SchemaInterface::RELATIONS]['one'][Relation::TARGET]); - $this->assertSame(Relation::LOAD_PROMISE, $schema['simple'][SchemaInterface::RELATIONS]['one'][Relation::LOAD]); + Assert::array($schema['simple'][SchemaInterface::RELATIONS])->hasKeys('one'); + Assert::same($schema['simple'][SchemaInterface::RELATIONS]['one'][Relation::TYPE], Relation::HAS_ONE); + Assert::same($schema['simple'][SchemaInterface::RELATIONS]['one'][Relation::TARGET], 'eComplete'); + Assert::same($schema['simple'][SchemaInterface::RELATIONS]['one'][Relation::LOAD], Relation::LOAD_PROMISE); } + #[Test] public function testInnerOuterKeys(): void { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures18'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures18'], 'exclude' => [], ]), ); @@ -89,21 +93,10 @@ public function testInnerOuterKeys(): void foreach ($checks as [$name, $innerKey, $outerKey]) { $relation = $schema['booking'][SchemaInterface::RELATIONS][$name]; - $this->assertSame(Relation::HAS_ONE, $relation[Relation::TYPE], "$name: relation type"); - $this->assertSame( - (array) $innerKey, - (array) $relation[Relation::SCHEMA][Relation::INNER_KEY], - "$name: Inner Key", - ); - $this->assertSame( - (array) $outerKey, - (array) $relation[Relation::SCHEMA][Relation::OUTER_KEY], - "$name: Outer Key", - ); + Assert::same($relation[Relation::TYPE], Relation::HAS_ONE, "$name: relation type"); + Assert::same((array) $relation[Relation::SCHEMA][Relation::INNER_KEY], (array) $innerKey, "$name: Inner Key"); + Assert::same((array) $relation[Relation::SCHEMA][Relation::OUTER_KEY], (array) $outerKey, "$name: Outer Key"); } - $this->assertArrayNotHasKey( - 'id_reservation', - $schema['booking'][SchemaInterface::COLUMNS], - ); + Assert::array($schema['booking'][SchemaInterface::COLUMNS])->doesNotHaveKeys('id_reservation'); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/InverseTestCase.php b/tests/Feature/Common/Relation/InverseTest.php similarity index 53% rename from tests/Annotated/Functional/Driver/Common/Relation/InverseTestCase.php rename to tests/Feature/Common/Relation/InverseTest.php index 95221068..6dbce47a 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/InverseTestCase.php +++ b/tests/Feature/Common/Relation/InverseTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures2\MarkedInterface; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\Schema\Compiler; @@ -21,18 +21,21 @@ use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Generator\ValidateEntities; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class InverseTestCase extends BaseTestCase +final class InverseTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testBelongsToOne(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures2'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures2'], 'exclude' => [], ])); @@ -53,20 +56,21 @@ public function testBelongsToOne(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('parent', $schema['eComplete'][Schema::RELATIONS]); - $this->assertSame(Relation::BELONGS_TO, $schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TYPE]); - $this->assertSame('simple', $schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TARGET]); + Assert::array($schema['eComplete'][Schema::RELATIONS])->hasKeys('parent'); + Assert::same($schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TYPE], Relation::BELONGS_TO); + Assert::same($schema['eComplete'][Schema::RELATIONS]['parent'][Relation::TARGET], 'simple'); - $this->assertArrayHasKey('child', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::HAS_ONE, $schema['simple'][Schema::RELATIONS]['child'][Relation::TYPE]); - $this->assertSame('eComplete', $schema['simple'][Schema::RELATIONS]['child'][Relation::TARGET]); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('child'); + Assert::same($schema['simple'][Schema::RELATIONS]['child'][Relation::TYPE], Relation::HAS_ONE); + Assert::same($schema['simple'][Schema::RELATIONS]['child'][Relation::TARGET], 'eComplete'); } #[DataProvider('allReadersProvider')] + #[Test] public function testBelongsToMany(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures2'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures2'], 'exclude' => [], ])); @@ -87,20 +91,21 @@ public function testBelongsToMany(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('uncles', $schema['eComplete'][Schema::RELATIONS]); - $this->assertSame(Relation::BELONGS_TO, $schema['eComplete'][Schema::RELATIONS]['uncles'][Relation::TYPE]); - $this->assertSame('simple', $schema['eComplete'][Schema::RELATIONS]['uncles'][Relation::TARGET]); + Assert::array($schema['eComplete'][Schema::RELATIONS])->hasKeys('uncles'); + Assert::same($schema['eComplete'][Schema::RELATIONS]['uncles'][Relation::TYPE], Relation::BELONGS_TO); + Assert::same($schema['eComplete'][Schema::RELATIONS]['uncles'][Relation::TARGET], 'simple'); - $this->assertArrayHasKey('stepKids', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::HAS_MANY, $schema['simple'][Schema::RELATIONS]['stepKids'][Relation::TYPE]); - $this->assertSame('eComplete', $schema['simple'][Schema::RELATIONS]['stepKids'][Relation::TARGET]); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('stepKids'); + Assert::same($schema['simple'][Schema::RELATIONS]['stepKids'][Relation::TYPE], Relation::HAS_MANY); + Assert::same($schema['simple'][Schema::RELATIONS]['stepKids'][Relation::TARGET], 'eComplete'); } #[DataProvider('allReadersProvider')] + #[Test] public function testHasOne(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures2'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures2'], 'exclude' => [], ])); @@ -121,20 +126,21 @@ public function testHasOne(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('simple', $schema['user'][Schema::RELATIONS]); - $this->assertSame(Relation::HAS_ONE, $schema['user'][Schema::RELATIONS]['simple'][Relation::TYPE]); - $this->assertSame('simple', $schema['user'][Schema::RELATIONS]['simple'][Relation::TARGET]); + Assert::array($schema['user'][Schema::RELATIONS])->hasKeys('simple'); + Assert::same($schema['user'][Schema::RELATIONS]['simple'][Relation::TYPE], Relation::HAS_ONE); + Assert::same($schema['user'][Schema::RELATIONS]['simple'][Relation::TARGET], 'simple'); - $this->assertArrayHasKey('user', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::BELONGS_TO, $schema['simple'][Schema::RELATIONS]['user'][Relation::TYPE]); - $this->assertSame('user', $schema['simple'][Schema::RELATIONS]['user'][Relation::TARGET]); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('user'); + Assert::same($schema['simple'][Schema::RELATIONS]['user'][Relation::TYPE], Relation::BELONGS_TO); + Assert::same($schema['simple'][Schema::RELATIONS]['user'][Relation::TARGET], 'user'); } #[DataProvider('allReadersProvider')] + #[Test] public function testHasOneInverseLoad(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures5'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures5'], 'exclude' => [], ])); @@ -155,24 +161,25 @@ public function testHasOneInverseLoad(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('simple', $schema['user'][Schema::RELATIONS]); - $this->assertSame(Relation::HAS_ONE, $schema['user'][Schema::RELATIONS]['simple'][Relation::TYPE]); - $this->assertSame('simple', $schema['user'][Schema::RELATIONS]['simple'][Relation::TARGET]); + Assert::array($schema['user'][Schema::RELATIONS])->hasKeys('simple'); + Assert::same($schema['user'][Schema::RELATIONS]['simple'][Relation::TYPE], Relation::HAS_ONE); + Assert::same($schema['user'][Schema::RELATIONS]['simple'][Relation::TARGET], 'simple'); - $this->assertSame(Relation::LOAD_EAGER, $schema['user'][Schema::RELATIONS]['simple'][Relation::LOAD]); + Assert::same($schema['user'][Schema::RELATIONS]['simple'][Relation::LOAD], Relation::LOAD_EAGER); - $this->assertArrayHasKey('user', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::BELONGS_TO, $schema['simple'][Schema::RELATIONS]['user'][Relation::TYPE]); - $this->assertSame('user', $schema['simple'][Schema::RELATIONS]['user'][Relation::TARGET]); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('user'); + Assert::same($schema['simple'][Schema::RELATIONS]['user'][Relation::TYPE], Relation::BELONGS_TO); + Assert::same($schema['simple'][Schema::RELATIONS]['user'][Relation::TARGET], 'user'); - $this->assertSame(Relation::LOAD_PROMISE, $schema['simple'][Schema::RELATIONS]['user'][Relation::LOAD]); + Assert::same($schema['simple'][Schema::RELATIONS]['user'][Relation::LOAD], Relation::LOAD_PROMISE); } #[DataProvider('allReadersProvider')] + #[Test] public function testBelongsTo(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures2'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures2'], 'exclude' => [], ])); @@ -193,16 +200,16 @@ public function testBelongsTo(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('owner', $schema['mark'][Schema::RELATIONS]); - $this->assertSame(Relation::BELONGS_TO_MORPHED, $schema['mark'][Schema::RELATIONS]['owner'][Relation::TYPE]); - $this->assertSame(MarkedInterface::class, $schema['mark'][Schema::RELATIONS]['owner'][Relation::TARGET]); + Assert::array($schema['mark'][Schema::RELATIONS])->hasKeys('owner'); + Assert::same($schema['mark'][Schema::RELATIONS]['owner'][Relation::TYPE], Relation::BELONGS_TO_MORPHED); + Assert::same($schema['mark'][Schema::RELATIONS]['owner'][Relation::TARGET], MarkedInterface::class); - $this->assertArrayHasKey('mark', $schema['user'][Schema::RELATIONS]); - $this->assertSame(Relation::MORPHED_HAS_ONE, $schema['user'][Schema::RELATIONS]['mark'][Relation::TYPE]); - $this->assertSame('mark', $schema['user'][Schema::RELATIONS]['mark'][Relation::TARGET]); + Assert::array($schema['user'][Schema::RELATIONS])->hasKeys('mark'); + Assert::same($schema['user'][Schema::RELATIONS]['mark'][Relation::TYPE], Relation::MORPHED_HAS_ONE); + Assert::same($schema['user'][Schema::RELATIONS]['mark'][Relation::TARGET], 'mark'); - $this->assertArrayHasKey('mark', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::MORPHED_HAS_ONE, $schema['simple'][Schema::RELATIONS]['mark'][Relation::TYPE]); - $this->assertSame('mark', $schema['simple'][Schema::RELATIONS]['mark'][Relation::TARGET]); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('mark'); + Assert::same($schema['simple'][Schema::RELATIONS]['mark'][Relation::TYPE], Relation::MORPHED_HAS_ONE); + Assert::same($schema['simple'][Schema::RELATIONS]['mark'][Relation::TARGET], 'mark'); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/ManyToManyTestCase.php b/tests/Feature/Common/Relation/ManyToManyTest.php similarity index 57% rename from tests/Annotated/Functional/Driver/Common/Relation/ManyToManyTestCase.php rename to tests/Feature/Common/Relation/ManyToManyTest.php index fbb1cdf5..60f4987c 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/ManyToManyTestCase.php +++ b/tests/Feature/Common/Relation/ManyToManyTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Collection\BaseCollection; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; use Cycle\Database\Schema\AbstractTable; use Cycle\ORM\Relation; use Cycle\ORM\SchemaInterface; @@ -22,21 +22,21 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Data\DataProvider; +use Testo\Test; -use function PHPUnit\Framework\assertCount; - -abstract class ManyToManyTestCase extends BaseTestCase +final class ManyToManyTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testPivotPrimaryKeys(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures15'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures15'], 'exclude' => [], ])); @@ -65,18 +65,16 @@ public function testPivotPrimaryKeys(ReaderInterface $reader): void assert($table instanceof AbstractTable); // Check MTM relation in the Schema - $this->assertSame(Relation::MANY_TO_MANY, $schema['post'][Schema::RELATIONS]['tags'][Relation::TYPE]); - $this->assertSame('tag', $schema['post'][Schema::RELATIONS]['tags'][Relation::TARGET]); - $this->assertSame( - 'context', - $schema['post'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_ENTITY], - ); + \Testo\Assert::same($schema['post'][Schema::RELATIONS]['tags'][Relation::TYPE], Relation::MANY_TO_MANY); + \Testo\Assert::same($schema['post'][Schema::RELATIONS]['tags'][Relation::TARGET], 'tag'); + \Testo\Assert::same($schema['post'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_ENTITY], 'context'); // Check table - assertCount(1, $table->getIndexes()); + \Testo\Assert::count($table->getIndexes(), 1); } #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -93,52 +91,29 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('tags', $schema['withTable'][Schema::RELATIONS]); + \Testo\Assert::array($schema['withTable'][Schema::RELATIONS])->hasKeys('tags'); - $this->assertSame( - Relation::MANY_TO_MANY, - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::TYPE], - ); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::TYPE], Relation::MANY_TO_MANY); - $this->assertSame( - 'tag', - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::TARGET], - ); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::TARGET], 'tag'); - $this->assertSame( - 'tagContext', - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_ENTITY], - ); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_ENTITY], 'tagContext'); - $this->assertSame( - ['withTable_id'], - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_INNER_KEY], - ); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_INNER_KEY], ['withTable_id']); - $this->assertSame( - ['tag_id'], - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_OUTER_KEY], - ); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::THROUGH_OUTER_KEY], ['tag_id']); - $this->assertSame( - ['id' => ['>=' => '1']], - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::WHERE], - ); - $this->assertSame( - ['id' => 'DESC'], - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::ORDER_BY], - ); - $this->assertSame( - BaseCollection::class, - $schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::COLLECTION_TYPE], - ); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::WHERE], ['id' => ['>=' => '1']]); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::ORDER_BY], ['id' => 'DESC']); + \Testo\Assert::same($schema['withTable'][Schema::RELATIONS]['tags'][Relation::SCHEMA][Relation::COLLECTION_TYPE], BaseCollection::class); } + #[Test] public function testInnerOuterKeys(): void { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures18'], + 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures18'], 'exclude' => [], ]), ); @@ -179,31 +154,12 @@ public function testInnerOuterKeys(): void $throughInnerKey = (array) $throughInnerKey; $throughOuterKey = (array) $throughOuterKey; - $this->assertSame(Relation::MANY_TO_MANY, $relation[Relation::TYPE], "$name: relation type"); - $this->assertSame( - $innerKey, - (array) $relation[Relation::SCHEMA][Relation::INNER_KEY], - "$name: Inner Key", - ); - $this->assertSame( - $outerKey, - (array) $relation[Relation::SCHEMA][Relation::OUTER_KEY], - "$name: Outer Key", - ); - $this->assertSame( - $throughInnerKey, - (array) $relation[Relation::SCHEMA][Relation::THROUGH_INNER_KEY], - "$name: Through inner Key", - ); - $this->assertSame( - $throughOuterKey, - (array) $relation[Relation::SCHEMA][Relation::THROUGH_OUTER_KEY], - "$name: Through outer Key", - ); + \Testo\Assert::same($relation[Relation::TYPE], Relation::MANY_TO_MANY, "$name: relation type"); + \Testo\Assert::same((array) $relation[Relation::SCHEMA][Relation::INNER_KEY], $innerKey, "$name: Inner Key"); + \Testo\Assert::same((array) $relation[Relation::SCHEMA][Relation::OUTER_KEY], $outerKey, "$name: Outer Key"); + \Testo\Assert::same((array) $relation[Relation::SCHEMA][Relation::THROUGH_INNER_KEY], $throughInnerKey, "$name: Through inner Key"); + \Testo\Assert::same((array) $relation[Relation::SCHEMA][Relation::THROUGH_OUTER_KEY], $throughOuterKey, "$name: Through outer Key"); } - $this->assertArrayNotHasKey( - 'booking_id_column', - $schema['booking_reservation'][SchemaInterface::COLUMNS], - ); + \Testo\Assert::array($schema['booking_reservation'][SchemaInterface::COLUMNS])->doesNotHaveKeys('booking_id_column'); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/BelongsToMorphedTestCase.php b/tests/Feature/Common/Relation/Morphed/BelongsToMorphedTest.php similarity index 65% rename from tests/Annotated/Functional/Driver/Common/Relation/Morphed/BelongsToMorphedTestCase.php rename to tests/Feature/Common/Relation/Morphed/BelongsToMorphedTest.php index 95830ac7..36e71f33 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/BelongsToMorphedTestCase.php +++ b/tests/Feature/Common/Relation/Morphed/BelongsToMorphedTest.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation\Morphed; +namespace Cycle\Annotated\Tests\Feature\Common\Relation\Morphed; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Constrain\SomeConstrain; use Cycle\Annotated\Tests\Fixtures\Fixtures1\LabelledInterface; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\SchemaInterface as Schema; use Cycle\Schema\Compiler; @@ -21,12 +21,15 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class BelongsToMorphedTestCase extends BaseTestCase +final class BelongsToMorphedTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -43,17 +46,11 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('owner', $schema['label'][Schema::RELATIONS]); - $this->assertSame( - Relation::BELONGS_TO_MORPHED, - $schema['label'][Schema::RELATIONS]['owner'][Relation::TYPE], - ); + Assert::array($schema['label'][Schema::RELATIONS])->hasKeys('owner'); + Assert::same($schema['label'][Schema::RELATIONS]['owner'][Relation::TYPE], Relation::BELONGS_TO_MORPHED); - $this->assertSame( - LabelledInterface::class, - $schema['label'][Schema::RELATIONS]['owner'][Relation::TARGET], - ); + Assert::same($schema['label'][Schema::RELATIONS]['owner'][Relation::TARGET], LabelledInterface::class); - $this->assertSame(SomeConstrain::class, $schema['label'][Schema::SCOPE]); + Assert::same($schema['label'][Schema::SCOPE], SomeConstrain::class); } } diff --git a/tests/Feature/Common/Relation/Morphed/MorphedHasManyTest.php b/tests/Feature/Common/Relation/Morphed/MorphedHasManyTest.php new file mode 100644 index 00000000..6233beb1 --- /dev/null +++ b/tests/Feature/Common/Relation/Morphed/MorphedHasManyTest.php @@ -0,0 +1,74 @@ +dbal); + + $schema = (new Compiler())->compile($r, [ + new Entities(new TokenizerEntityLocator($this->locator, $reader), $reader), + new ResetTables(), + new MergeColumns($reader), + new GenerateRelations(), + new RenderTables(), + new RenderRelations(), + new MergeIndexes($reader), + new SyncTables(), + new GenerateTypecast(), + ]); + + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('labels'); + Assert::same($schema['simple'][Schema::RELATIONS]['labels'][Relation::TYPE], Relation::MORPHED_HAS_MANY); + Assert::same($schema['simple'][Schema::RELATIONS]['labels'][Relation::TARGET], 'label'); + + Assert::array($schema['withTable'][Schema::RELATIONS])->hasKeys('labels'); + Assert::same($schema['withTable'][Schema::RELATIONS]['labels'][Relation::TYPE], Relation::MORPHED_HAS_MANY); + + Assert::same($schema['withTable'][Schema::RELATIONS]['labels'][Relation::TARGET], 'label'); + + Assert::true($this->dbal->database('default') + ->getDriver() + ->getSchema('labels') + ->hasColumn('owner_id')); + + Assert::true($this->dbal->database('default') + ->getDriver() + ->getSchema('labels') + ->hasColumn('owner_role')); + + Assert::false($this->dbal->database('default') + ->getDriver() + ->getSchema('labels') + ->hasIndex(['owner_id', 'owner_role'])); + + Assert::same($schema['simple'][\Cycle\ORM\SchemaInterface::RELATIONS]['labels'][Relation::SCHEMA][Relation::COLLECTION_TYPE], BaseCollection::class); + } +} diff --git a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/MorphedHasOneTestCase.php b/tests/Feature/Common/Relation/Morphed/MorphedHasOneTest.php similarity index 51% rename from tests/Annotated/Functional/Driver/Common/Relation/Morphed/MorphedHasOneTestCase.php rename to tests/Feature/Common/Relation/Morphed/MorphedHasOneTest.php index 668e044d..f24dd130 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/MorphedHasOneTestCase.php +++ b/tests/Feature/Common/Relation/Morphed/MorphedHasOneTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation\Morphed; +namespace Cycle\Annotated\Tests\Feature\Common\Relation\Morphed; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\Schema\Compiler; @@ -19,12 +19,15 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class MorphedHasOneTestCase extends BaseTestCase +final class MorphedHasOneTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -41,29 +44,23 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('label', $schema['tag'][Schema::RELATIONS]); - $this->assertSame(Relation::MORPHED_HAS_ONE, $schema['tag'][Schema::RELATIONS]['label'][Relation::TYPE]); - $this->assertSame('label', $schema['tag'][Schema::RELATIONS]['label'][Relation::TARGET]); + Assert::array($schema['tag'][Schema::RELATIONS])->hasKeys('label'); + Assert::same($schema['tag'][Schema::RELATIONS]['label'][Relation::TYPE], Relation::MORPHED_HAS_ONE); + Assert::same($schema['tag'][Schema::RELATIONS]['label'][Relation::TARGET], 'label'); - $this->assertTrue( - $this->dbal->database('default') - ->getDriver() - ->getSchema('labels') - ->hasColumn('owner_id'), - ); + Assert::true($this->dbal->database('default') + ->getDriver() + ->getSchema('labels') + ->hasColumn('owner_id')); - $this->assertTrue( - $this->dbal->database('default') - ->getDriver() - ->getSchema('labels') - ->hasColumn('owner_role'), - ); + Assert::true($this->dbal->database('default') + ->getDriver() + ->getSchema('labels') + ->hasColumn('owner_role')); - $this->assertFalse( - $this->dbal->database('default') - ->getDriver() - ->getSchema('labels') - ->hasIndex(['owner_id', 'owner_role']), - ); + Assert::false($this->dbal->database('default') + ->getDriver() + ->getSchema('labels') + ->hasIndex(['owner_id', 'owner_role'])); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/RefersToMorphedTestCase.php b/tests/Feature/Common/Relation/Morphed/RefersToMorphedTest.php similarity index 63% rename from tests/Annotated/Functional/Driver/Common/Relation/Morphed/RefersToMorphedTestCase.php rename to tests/Feature/Common/Relation/Morphed/RefersToMorphedTest.php index 373f2a35..d023fa3a 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/Morphed/RefersToMorphedTestCase.php +++ b/tests/Feature/Common/Relation/Morphed/RefersToMorphedTest.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation\Morphed; +namespace Cycle\Annotated\Tests\Feature\Common\Relation\Morphed; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\RefersToMorphed\MorphedParentInterface; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\SchemaInterface as Schema; use Cycle\Schema\Compiler; @@ -20,18 +20,21 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class RefersToMorphedTestCase extends BaseTestCase +final class RefersToMorphedTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $locator = (new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../../Fixtures/RefersToMorphed'], + 'directories' => [__DIR__ . '/../../../../Fixtures/RefersToMorphed'], 'exclude' => [], ])))->classLocator(); @@ -49,18 +52,12 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('parent', $schema['comment'][Schema::RELATIONS]); - $this->assertSame( - Relation::REFERS_TO_MORPHED, - $schema['comment'][Schema::RELATIONS]['parent'][Relation::TYPE], - ); - $this->assertSame( - MorphedParentInterface::class, - $schema['comment'][Schema::RELATIONS]['parent'][Relation::TARGET], - ); + Assert::array($schema['comment'][Schema::RELATIONS])->hasKeys('parent'); + Assert::same($schema['comment'][Schema::RELATIONS]['parent'][Relation::TYPE], Relation::REFERS_TO_MORPHED); + Assert::same($schema['comment'][Schema::RELATIONS]['parent'][Relation::TARGET], MorphedParentInterface::class); // Morphed refers-to stores the outer key and the target role on the source entity. - $this->assertContains('parent_id', $schema['comment'][Schema::COLUMNS]); - $this->assertContains('parent_role', $schema['comment'][Schema::COLUMNS]); + Assert::contains($schema['comment'][Schema::COLUMNS], 'parent_id'); + Assert::contains($schema['comment'][Schema::COLUMNS], 'parent_role'); } } diff --git a/tests/Annotated/Functional/Driver/Common/Relation/RefersToTestCase.php b/tests/Feature/Common/Relation/RefersToTest.php similarity index 59% rename from tests/Annotated/Functional/Driver/Common/Relation/RefersToTestCase.php rename to tests/Feature/Common/Relation/RefersToTest.php index 86396098..66694906 100644 --- a/tests/Annotated/Functional/Driver/Common/Relation/RefersToTestCase.php +++ b/tests/Feature/Common/Relation/RefersToTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common\Relation; +namespace Cycle\Annotated\Tests\Feature\Common\Relation; use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; -use Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Relation; use Cycle\ORM\Schema; use Cycle\Schema\Compiler; @@ -19,12 +19,15 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class RefersToTestCase extends BaseTestCase +final class RefersToTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testRelation(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -41,17 +44,14 @@ public function testRelation(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertArrayHasKey('parent', $schema['simple'][Schema::RELATIONS]); - $this->assertSame(Relation::REFERS_TO, $schema['simple'][Schema::RELATIONS]['parent'][Relation::TYPE]); - $this->assertSame('simple', $schema['simple'][Schema::RELATIONS]['parent'][Relation::TARGET]); + Assert::array($schema['simple'][Schema::RELATIONS])->hasKeys('parent'); + Assert::same($schema['simple'][Schema::RELATIONS]['parent'][Relation::TYPE], Relation::REFERS_TO); + Assert::same($schema['simple'][Schema::RELATIONS]['parent'][Relation::TARGET], 'simple'); - $this->assertSame( - 'NO ACTION', - $this->dbal->database('default') - ->getDriver() - ->getSchema('simples') - ->foreignKey(['parent_id']) - ->getDeleteRule(), - ); + Assert::same($this->dbal->database('default') + ->getDriver() + ->getSchema('simples') + ->foreignKey(['parent_id']) + ->getDeleteRule(), 'NO ACTION'); } } diff --git a/tests/Annotated/Functional/Driver/Common/SchemaModifiersTestCase.php b/tests/Feature/Common/SchemaModifiersTest.php similarity index 74% rename from tests/Annotated/Functional/Driver/Common/SchemaModifiersTestCase.php rename to tests/Feature/Common/SchemaModifiersTest.php index 3c23b00f..07f77cdc 100644 --- a/tests/Annotated/Functional/Driver/Common/SchemaModifiersTestCase.php +++ b/tests/Feature/Common/SchemaModifiersTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -10,6 +10,7 @@ use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Child; use Cycle\Annotated\Tests\Fixtures\Fixtures17\MapperSegmentSchemaModifier; use Cycle\Annotated\Tests\Fixtures\Fixtures17\ParentSegmentSchemaModifier; @@ -22,19 +23,22 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class SchemaModifiersTestCase extends BaseTestCase +final class SchemaModifiersTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testModifierAnnotationShouldBeAddedToEntity(ReaderInterface $reader): void { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures17'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures17'], 'exclude' => [], ]), ); @@ -59,11 +63,11 @@ public function testModifierAnnotationShouldBeAddedToEntity(ReaderInterface $rea $post = $r->getEntity('post'); $modifiers = iterator_to_array($post->getSchemaModifiers()); - $this->assertCount(2, $modifiers); - $this->assertInstanceOf(ParentSegmentSchemaModifier::class, $modifiers[0]); - $this->assertInstanceOf(MapperSegmentSchemaModifier::class, $modifiers[1]); + Assert::count($modifiers, 2); + Assert::instanceOf($modifiers[0], ParentSegmentSchemaModifier::class); + Assert::instanceOf($modifiers[1], MapperSegmentSchemaModifier::class); - $this->assertSame(\stdClass::class, $schema['post'][SchemaInterface::PARENT]); - $this->assertSame(Child::class, $schema['post'][SchemaInterface::MAPPER]); + Assert::same($schema['post'][SchemaInterface::PARENT], \stdClass::class); + Assert::same($schema['post'][SchemaInterface::MAPPER], Child::class); } } diff --git a/tests/Annotated/Functional/Driver/Common/TableTestCase.php b/tests/Feature/Common/TableTest.php similarity index 73% rename from tests/Annotated/Functional/Driver/Common/TableTestCase.php rename to tests/Feature/Common/TableTest.php index 611a5c3e..d5737448 100644 --- a/tests/Annotated/Functional/Driver/Common/TableTestCase.php +++ b/tests/Feature/Common/TableTest.php @@ -2,28 +2,32 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Entities; use Cycle\Annotated\Exception\AnnotationException; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\ORM\Schema; use Cycle\Schema\Compiler; use Cycle\Schema\Generator\ForeignKeys; use Cycle\Schema\Generator\RenderTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\AnnotationReader; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\Composite\SelectiveReader; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Expect; +use Testo\Test; -abstract class TableTestCase extends BaseTestCase +final class TableTest extends BaseTestCase { public static function foreignKeyDirectoriesDataProvider(): \Traversable { @@ -77,6 +81,7 @@ public static function foreignKeyDirectoriesDataProvider(): \Traversable } #[DataProvider('allReadersProvider')] + #[Test] public function testColumnsRendered(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -84,21 +89,22 @@ public function testColumnsRendered(ReaderInterface $reader): void (new MergeColumns($reader))->run($r); (new RenderTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('withTable'))); + Assert::true($r->hasTable($r->getEntity('withTable'))); $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertTrue($schema->hasColumn('name')); - $this->assertSame('string', $schema->column('status')->getType()); + Assert::true($schema->hasColumn('name')); + Assert::same($schema->column('status')->getType(), 'string'); - $this->assertTrue($schema->hasColumn('status')); + Assert::true($schema->hasColumn('status')); - $this->assertSame('enum', $schema->column('status')->getAbstractType()); - $this->assertSame('active', $schema->column('status')->getDefaultValue()); - $this->assertSame(['active', 'disabled'], $schema->column('status')->getEnumValues()); + Assert::same($schema->column('status')->getAbstractType(), 'enum'); + Assert::same($schema->column('status')->getDefaultValue(), 'active'); + Assert::same($schema->column('status')->getEnumValues(), ['active', 'disabled']); } #[DataProvider('allReadersProvider')] + #[Test] public function testColumnWithDifferentColumnNameAndProperty(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -110,12 +116,13 @@ public function testColumnWithDifferentColumnNameAndProperty(ReaderInterface $re new RenderTables(), ], ); - $this->assertArrayHasKey('withTable', $schema); - $this->assertArrayHasKey('status_property', $schema['withTable'][Schema::COLUMNS]); - $this->assertSame('status', $schema['withTable'][Schema::COLUMNS]['status_property']); + Assert::array($schema)->hasKeys('withTable'); + Assert::array($schema['withTable'][Schema::COLUMNS])->hasKeys('status_property'); + Assert::same($schema['withTable'][Schema::COLUMNS]['status_property'], 'status'); } #[DataProvider('allReadersProvider')] + #[Test] public function testColumnWithoutColumnName(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -127,16 +134,17 @@ public function testColumnWithoutColumnName(ReaderInterface $reader): void new RenderTables(), ], ); - $this->assertArrayHasKey('withTable', $schema); - $this->assertArrayHasKey('no_column_name', $schema['withTable'][Schema::COLUMNS]); - $this->assertSame('no_column_name', $schema['withTable'][Schema::COLUMNS]['no_column_name']); + Assert::array($schema)->hasKeys('withTable'); + Assert::array($schema['withTable'][Schema::COLUMNS])->hasKeys('no_column_name'); + Assert::same($schema['withTable'][Schema::COLUMNS]['no_column_name'], 'no_column_name'); } + #[Test] public function testColumnInTableAnnotationByNumericKey(): void { $reader = new AnnotationReader(); $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures9'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures9'], 'exclude' => [], ])); $locator = $tokenizer->classLocator(); @@ -147,26 +155,24 @@ public function testColumnInTableAnnotationByNumericKey(): void new RenderTables(), ]); - $this->assertArrayHasKey('orderedIdx', $schema); - $this->assertArrayHasKey('other_name', $schema['orderedIdx'][Schema::COLUMNS]); - $this->assertSame('other_name', $schema['orderedIdx'][Schema::COLUMNS]['other_name']); + Assert::array($schema)->hasKeys('orderedIdx'); + Assert::array($schema['orderedIdx'][Schema::COLUMNS])->hasKeys('other_name'); + Assert::same($schema['orderedIdx'][Schema::COLUMNS]['other_name'], 'other_name'); } + #[Test] public function testColumnWithPropertyInTableAnnotationByNamedKey(): void { $reader = new AnnotationReader(); $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures11'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures11'], 'exclude' => [], ])); $locator = $tokenizer->classLocator(); $r = new Registry($this->dbal); - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage( - 'Can not use name "name1" for Column of the `badEntity` role, because the ' - . '"property" field of the metadata class has already been set to "name2".', - ); + Expect::exception(AnnotationException::class)->withMessageContaining('Can not use name "name1" for Column of the `badEntity` role, because the ' + . '"property" field of the metadata class has already been set to "name2".'); (new Compiler())->compile($r, [ new Entities(new TokenizerEntityLocator($locator, $reader), $reader), @@ -176,12 +182,13 @@ public function testColumnWithPropertyInTableAnnotationByNamedKey(): void } #[DataProvider('singularReadersProvider')] + #[Test] public function testCompositePrimaryKey(ReaderInterface $reader): void { $r = new Registry($this->dbal); $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures12'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures12'], 'exclude' => [], ])); $locator = $tokenizer->classLocator(); @@ -194,19 +201,19 @@ public function testCompositePrimaryKey(ReaderInterface $reader): void $schema = $r->getTableSchema($r->getEntity('compositePost')); - $this->assertEquals(['id', 'user_id'], $schema->getPrimaryKeys()); + Assert::equals($schema->getPrimaryKeys(), ['id', 'user_id']); } #[DataProvider('singularReadersProvider')] + #[Test] public function testIndexWithEmptyColumnsShouldThrowAnException(ReaderInterface $reader): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('Invalid index definition for `compositePost`. Column list can\'t be empty.'); + Expect::exception(AnnotationException::class)->withMessageContaining('Invalid index definition for `compositePost`. Column list can\'t be empty.'); $r = new Registry($this->dbal); $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures13'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures13'], 'exclude' => [], ])); $locator = $tokenizer->classLocator(); @@ -218,6 +225,7 @@ public function testIndexWithEmptyColumnsShouldThrowAnException(ReaderInterface } #[DataProvider('allReadersProvider')] + #[Test] public function testIndexes(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -228,22 +236,23 @@ public function testIndexes(ReaderInterface $reader): void (new MergeIndexes($reader))->run($r); (new SyncTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('withTable'))); + Assert::true($r->hasTable($r->getEntity('withTable'))); $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertTrue($schema->hasIndex(['name'])); - $this->assertTrue($schema->index(['name'])->isUnique()); - $this->assertSame('name_index', $schema->index(['name'])->getName()); + Assert::true($schema->hasIndex(['name'])); + Assert::true($schema->index(['name'])->isUnique()); + Assert::same($schema->index(['name'])->getName(), 'name_index'); - $this->assertTrue($schema->hasIndex(['status'])); + Assert::true($schema->hasIndex(['status'])); } #[DataProvider('singularReadersProvider')] + #[Test] public function testOrderedIndexes(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures9'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures9'], 'exclude' => [], ])); @@ -257,15 +266,16 @@ public function testOrderedIndexes(ReaderInterface $reader): void (new MergeIndexes($reader))->run($r); (new SyncTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('orderedIdx'))); + Assert::true($r->hasTable($r->getEntity('orderedIdx'))); $schema = $r->getTableSchema($r->getEntity('orderedIdx')); - $this->assertTrue($schema->hasColumn('name')); - $this->assertTrue($schema->hasIndex(['name', 'id DESC'])); + Assert::true($schema->hasColumn('name')); + Assert::true($schema->hasIndex(['name', 'id DESC'])); } #[DataProvider('allReadersProvider')] + #[Test] public function testNamingDefault(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -273,14 +283,15 @@ public function testNamingDefault(ReaderInterface $reader): void (new MergeColumns($reader))->run($r); (new RenderTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('withTable'))); + Assert::true($r->hasTable($r->getEntity('withTable'))); $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertSame('with_tables', $schema->getName()); + Assert::same($schema->getName(), 'with_tables'); } #[DataProvider('allReadersProvider')] + #[Test] public function testNamingPluralize(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -292,14 +303,15 @@ public function testNamingPluralize(ReaderInterface $reader): void (new MergeColumns($reader))->run($r); (new RenderTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('withTable'))); + Assert::true($r->hasTable($r->getEntity('withTable'))); $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertSame('with_tables', $schema->getName()); + Assert::same($schema->getName(), 'with_tables'); } #[DataProvider('allReadersProvider')] + #[Test] public function testNamingSingular(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -311,14 +323,15 @@ public function testNamingSingular(ReaderInterface $reader): void (new MergeColumns($reader))->run($r); (new RenderTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('withTable'))); + Assert::true($r->hasTable($r->getEntity('withTable'))); $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertSame('with_table', $schema->getName()); + Assert::same($schema->getName(), 'with_table'); } #[DataProvider('allReadersProvider')] + #[Test] public function testNamingNone(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -330,14 +343,15 @@ public function testNamingNone(ReaderInterface $reader): void (new MergeColumns($reader))->run($r); (new RenderTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('withTable'))); + Assert::true($r->hasTable($r->getEntity('withTable'))); $schema = $r->getTableSchema($r->getEntity('withTable')); - $this->assertSame('with_table', $schema->getName()); + Assert::same($schema->getName(), 'with_table'); } #[DataProvider('allReadersProvider')] + #[Test] public function testReadonlySchema(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -345,14 +359,15 @@ public function testReadonlySchema(ReaderInterface $reader): void (new MergeColumns($reader))->run($r); (new RenderTables())->run($r); - $this->assertTrue($r->hasTable($r->getEntity('simple'))); + Assert::true($r->hasTable($r->getEntity('simple'))); $schema = $r->getTableSchema($r->getEntity('simple')); - $this->assertTrue($schema->column('read_only_column')->isReadonlySchema()); + Assert::true($schema->column('read_only_column')->isReadonlySchema()); } #[DataProvider('foreignKeyDirectoriesDataProvider')] + #[Test] public function testForeignKeysAnnotationReader( ReaderInterface $reader, string $directory, @@ -360,7 +375,7 @@ public function testForeignKeysAnnotationReader( ): void { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [dirname(__DIR__, 3) . $directory], + 'directories' => [dirname(__DIR__, 2) . $directory], 'exclude' => [], ]), ); @@ -381,12 +396,12 @@ public function testForeignKeysAnnotationReader( $foreignKeys = $registry->getTableSchema($registry->getEntity('from'))->getForeignKeys(); $expectedFk = array_shift($foreignKeys); - $this->assertStringContainsString('from', $expectedFk->getTable()); - $this->assertStringContainsString('to', $expectedFk->getForeignTable()); - $this->assertSame(['inner_key'], $expectedFk->getColumns()); - $this->assertSame([$outerKey], $expectedFk->getForeignKeys()); - $this->assertSame('CASCADE', $expectedFk->getDeleteRule()); - $this->assertSame('CASCADE', $expectedFk->getUpdateRule()); - $this->assertTrue($expectedFk->hasIndex()); + Assert::string($expectedFk->getTable())->contains('from'); + Assert::string($expectedFk->getForeignTable())->contains('to'); + Assert::same($expectedFk->getColumns(), ['inner_key']); + Assert::same($expectedFk->getForeignKeys(), [$outerKey]); + Assert::same($expectedFk->getDeleteRule(), 'CASCADE'); + Assert::same($expectedFk->getUpdateRule(), 'CASCADE'); + Assert::true($expectedFk->hasIndex()); } } diff --git a/tests/Annotated/Functional/Driver/Common/TypecastTestCase.php b/tests/Feature/Common/TypecastTest.php similarity index 76% rename from tests/Annotated/Functional/Driver/Common/TypecastTestCase.php rename to tests/Feature/Common/TypecastTest.php index 4e8771b7..c8f324c5 100644 --- a/tests/Annotated/Functional/Driver/Common/TypecastTestCase.php +++ b/tests/Feature/Common/TypecastTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\Common; +namespace Cycle\Annotated\Tests\Feature\Common; use Cycle\Annotated\Embeddings; use Cycle\Annotated\Entities; @@ -10,6 +10,7 @@ use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; use Cycle\Annotated\MergeIndexes; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Typecast\Typecaster; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Typecast\UuidTypecaster; use Cycle\Annotated\Tests\Fixtures\Fixtures19\BackedEnum; @@ -24,14 +25,17 @@ use Cycle\Schema\Generator\ResetTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\DataProvider; use Spiral\Attributes\ReaderInterface; use Spiral\Tokenizer\Config\TokenizerConfig; use Spiral\Tokenizer\Tokenizer; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -abstract class TypecastTestCase extends BaseTestCase +final class TypecastTest extends BaseTestCase { #[DataProvider('allReadersProvider')] + #[Test] public function testEntityWithDefinedTypecastAsString(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -41,13 +45,11 @@ public function testEntityWithDefinedTypecastAsString(ReaderInterface $reader): new MergeColumns($reader), ]); - $this->assertSame( - Typecaster::class, - $schema['simple'][Schema::TYPECAST_HANDLER], - ); + Assert::same($schema['simple'][Schema::TYPECAST_HANDLER], Typecaster::class); } #[DataProvider('allReadersProvider')] + #[Test] public function testEntityWithDefinedTypecastAsArray(ReaderInterface $reader): void { $r = new Registry($this->dbal); @@ -57,21 +59,19 @@ public function testEntityWithDefinedTypecastAsArray(ReaderInterface $reader): v new MergeColumns($reader), ]); - $this->assertSame( - [ - Typecaster::class, - UuidTypecaster::class, - 'foo', - ], - $schema['tag'][Schema::TYPECAST_HANDLER], - ); + Assert::same($schema['tag'][Schema::TYPECAST_HANDLER], [ + Typecaster::class, + UuidTypecaster::class, + 'foo', + ]); } #[DataProvider('allReadersProvider')] + #[Test] public function testBackedEnum(ReaderInterface $reader): void { $tokenizer = new Tokenizer(new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../Fixtures/Fixtures19'], + 'directories' => [__DIR__ . '/../../Fixtures/Fixtures19'], 'exclude' => [], ])); @@ -92,13 +92,10 @@ public function testBackedEnum(ReaderInterface $reader): void new GenerateTypecast(), ]); - $this->assertSame( - [ - 'bid' => 'int', - 'be' => BackedEnum::class, - 'bew' => [BackedEnumWrapper::class, 'typecast'], - ], - $schema['booking'][SchemaInterface::TYPECAST], - ); + Assert::same($schema['booking'][SchemaInterface::TYPECAST], [ + 'bid' => 'int', + 'be' => BackedEnum::class, + 'bew' => [BackedEnumWrapper::class, 'typecast'], + ]); } } diff --git a/tests/Annotated/Functional/Driver/MySQL/TableTest.php b/tests/Feature/MySQL/TableTest.php similarity index 58% rename from tests/Annotated/Functional/Driver/MySQL/TableTest.php rename to tests/Feature/MySQL/TableTest.php index 6444b69c..4de3aa9b 100644 --- a/tests/Annotated/Functional/Driver/MySQL/TableTest.php +++ b/tests/Feature/MySQL/TableTest.php @@ -2,25 +2,25 @@ declare(strict_types=1); -namespace Cycle\Annotated\Tests\Functional\Driver\MySQL; +namespace Cycle\Annotated\Tests\Feature\MySQL; -// phpcs:ignore use Cycle\Annotated\Entities; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\MergeColumns; -use Cycle\Annotated\Tests\Functional\Driver\Common\TableTestCase; +use Cycle\Annotated\Tests\Feature\BaseTestCase; use Cycle\Schema\Generator\RenderTables; use Cycle\Schema\Generator\SyncTables; use Cycle\Schema\Registry; -use PHPUnit\Framework\Attributes\Group; use Spiral\Attributes\AttributeReader; +use Testo\Assert; +use Testo\Test; -#[Group('driver')] -#[Group('driver-mysql')] -final class TableTest extends TableTestCase +/** + * MySQL-only column options: unsigned, zerofill, charset and collation. + */ +final class TableTest extends BaseTestCase { - public const DRIVER = 'mysql'; - + #[Test] public function testUnsigned(): void { $reader = new AttributeReader(); @@ -31,15 +31,16 @@ public function testUnsigned(): void $schema = $r->getTableSchema($r->getEntity('label')); - $this->assertTrue($schema->column('unsigned')->isUnsigned()); - $this->assertFalse($schema->column('simple')->isUnsigned()); + Assert::true($schema->column('unsigned')->isUnsigned()); + Assert::false($schema->column('simple')->isUnsigned()); $schema->save(); - $this->assertTrue($this->dbal->database()->table('labels')->getSchema()->column('unsigned')->isUnsigned()); - $this->assertFalse($this->dbal->database()->table('labels')->getSchema()->column('simple')->isUnsigned()); + Assert::true($this->dbal->database()->table('labels')->getSchema()->column('unsigned')->isUnsigned()); + Assert::false($this->dbal->database()->table('labels')->getSchema()->column('simple')->isUnsigned()); } + #[Test] public function testZerofill(): void { $reader = new AttributeReader(); @@ -50,15 +51,16 @@ public function testZerofill(): void $schema = $r->getTableSchema($r->getEntity('label')); - $this->assertTrue($schema->column('zerofill')->isZerofill()); - $this->assertFalse($schema->column('simple')->isZerofill()); + Assert::true($schema->column('zerofill')->isZerofill()); + Assert::false($schema->column('simple')->isZerofill()); $schema->save(); - $this->assertTrue($this->dbal->database()->table('labels')->getSchema()->column('zerofill')->isUnsigned()); - $this->assertFalse($this->dbal->database()->table('labels')->getSchema()->column('simple')->isUnsigned()); + Assert::true($this->dbal->database()->table('labels')->getSchema()->column('zerofill')->isUnsigned()); + Assert::false($this->dbal->database()->table('labels')->getSchema()->column('simple')->isUnsigned()); } + #[Test] public function testColumnCustomAttributes(): void { $reader = new AttributeReader(); @@ -71,7 +73,7 @@ public function testColumnCustomAttributes(): void $dbSchema = $this->dbal->database()->table('labels')->getSchema(); $attributes = $dbSchema->column('charset_column')->getAttributes(); - $this->assertSame('ascii', $attributes['charset']); - $this->assertSame('ascii_bin', $attributes['collation']); + Assert::same($attributes['charset'], 'ascii'); + Assert::same($attributes['collation'], 'ascii_bin'); } } diff --git a/tests/Feature/Postgres/GeneratedFieldsTest.php b/tests/Feature/Postgres/GeneratedFieldsTest.php new file mode 100644 index 00000000..431cd277 --- /dev/null +++ b/tests/Feature/Postgres/GeneratedFieldsTest.php @@ -0,0 +1,50 @@ + [__DIR__ . '/../../Fixtures/Fixtures25/PostgreSQL'], + 'exclude' => [], + ])); + + $locator = $tokenizer->classLocator(); + + $r = new Registry($this->dbal); + + $schema = (new Compiler())->compile($r, [ + new Entities(new TokenizerEntityLocator($locator, $reader), $reader), + ]); + + Assert::same($schema['withGeneratedSerial'][SchemaInterface::GENERATED_FIELDS], [ + 'id' => GeneratedField::ON_INSERT, + 'smallSerial' => GeneratedField::ON_INSERT, + 'serial' => GeneratedField::ON_INSERT, + 'bigSerial' => GeneratedField::ON_INSERT, + ]); + } +} diff --git a/tests/Annotated/Fixtures/Fixtures1/AnotherClass.php b/tests/Fixtures/Fixtures1/AnotherClass.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/AnotherClass.php rename to tests/Fixtures/Fixtures1/AnotherClass.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Child.php b/tests/Fixtures/Fixtures1/Child.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Child.php rename to tests/Fixtures/Fixtures1/Child.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Collection/BaseCollection.php b/tests/Fixtures/Fixtures1/Collection/BaseCollection.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Collection/BaseCollection.php rename to tests/Fixtures/Fixtures1/Collection/BaseCollection.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Complete.php b/tests/Fixtures/Fixtures1/Complete.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Complete.php rename to tests/Fixtures/Fixtures1/Complete.php diff --git a/tests/Annotated/Fixtures/Fixtures1/CompleteMapper.php b/tests/Fixtures/Fixtures1/CompleteMapper.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/CompleteMapper.php rename to tests/Fixtures/Fixtures1/CompleteMapper.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Constrain/SomeConstrain.php b/tests/Fixtures/Fixtures1/Constrain/SomeConstrain.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Constrain/SomeConstrain.php rename to tests/Fixtures/Fixtures1/Constrain/SomeConstrain.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Label.php b/tests/Fixtures/Fixtures1/Label.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Label.php rename to tests/Fixtures/Fixtures1/Label.php diff --git a/tests/Annotated/Fixtures/Fixtures1/LabelledInterface.php b/tests/Fixtures/Fixtures1/LabelledInterface.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/LabelledInterface.php rename to tests/Fixtures/Fixtures1/LabelledInterface.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Repository/CompleteRepository.php b/tests/Fixtures/Fixtures1/Repository/CompleteRepository.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Repository/CompleteRepository.php rename to tests/Fixtures/Fixtures1/Repository/CompleteRepository.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Simple.php b/tests/Fixtures/Fixtures1/Simple.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Simple.php rename to tests/Fixtures/Fixtures1/Simple.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Source/TestSource.php b/tests/Fixtures/Fixtures1/Source/TestSource.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Source/TestSource.php rename to tests/Fixtures/Fixtures1/Source/TestSource.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Tag.php b/tests/Fixtures/Fixtures1/Tag.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Tag.php rename to tests/Fixtures/Fixtures1/Tag.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Tag/Context.php b/tests/Fixtures/Fixtures1/Tag/Context.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Tag/Context.php rename to tests/Fixtures/Fixtures1/Tag/Context.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Third.php b/tests/Fixtures/Fixtures1/Third.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Third.php rename to tests/Fixtures/Fixtures1/Third.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Typecast/Typecaster.php b/tests/Fixtures/Fixtures1/Typecast/Typecaster.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Typecast/Typecaster.php rename to tests/Fixtures/Fixtures1/Typecast/Typecaster.php diff --git a/tests/Annotated/Fixtures/Fixtures1/Typecast/UuidTypecaster.php b/tests/Fixtures/Fixtures1/Typecast/UuidTypecaster.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/Typecast/UuidTypecaster.php rename to tests/Fixtures/Fixtures1/Typecast/UuidTypecaster.php diff --git a/tests/Annotated/Fixtures/Fixtures1/WithTable.php b/tests/Fixtures/Fixtures1/WithTable.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures1/WithTable.php rename to tests/Fixtures/Fixtures1/WithTable.php diff --git a/tests/Annotated/Fixtures/Fixtures10/MergedMetadata.php b/tests/Fixtures/Fixtures10/MergedMetadata.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures10/MergedMetadata.php rename to tests/Fixtures/Fixtures10/MergedMetadata.php diff --git a/tests/Annotated/Fixtures/Fixtures11/BadEntity.php b/tests/Fixtures/Fixtures11/BadEntity.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures11/BadEntity.php rename to tests/Fixtures/Fixtures11/BadEntity.php diff --git a/tests/Annotated/Fixtures/Fixtures12/CompositePost.php b/tests/Fixtures/Fixtures12/CompositePost.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures12/CompositePost.php rename to tests/Fixtures/Fixtures12/CompositePost.php diff --git a/tests/Annotated/Fixtures/Fixtures13/CompositePost.php b/tests/Fixtures/Fixtures13/CompositePost.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures13/CompositePost.php rename to tests/Fixtures/Fixtures13/CompositePost.php diff --git a/tests/Annotated/Fixtures/Fixtures14/Article.php b/tests/Fixtures/Fixtures14/Article.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures14/Article.php rename to tests/Fixtures/Fixtures14/Article.php diff --git a/tests/Annotated/Fixtures/Fixtures14/Post.php b/tests/Fixtures/Fixtures14/Post.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures14/Post.php rename to tests/Fixtures/Fixtures14/Post.php diff --git a/tests/Annotated/Fixtures/Fixtures14/Some.php b/tests/Fixtures/Fixtures14/Some.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures14/Some.php rename to tests/Fixtures/Fixtures14/Some.php diff --git a/tests/Annotated/Fixtures/Fixtures14/Tag.php b/tests/Fixtures/Fixtures14/Tag.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures14/Tag.php rename to tests/Fixtures/Fixtures14/Tag.php diff --git a/tests/Annotated/Fixtures/Fixtures15/Context.php b/tests/Fixtures/Fixtures15/Context.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures15/Context.php rename to tests/Fixtures/Fixtures15/Context.php diff --git a/tests/Annotated/Fixtures/Fixtures15/Post.php b/tests/Fixtures/Fixtures15/Post.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures15/Post.php rename to tests/Fixtures/Fixtures15/Post.php diff --git a/tests/Annotated/Fixtures/Fixtures15/Tag.php b/tests/Fixtures/Fixtures15/Tag.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures15/Tag.php rename to tests/Fixtures/Fixtures15/Tag.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Beaver.php b/tests/Fixtures/Fixtures16/Beaver.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Beaver.php rename to tests/Fixtures/Fixtures16/Beaver.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Buyer.php b/tests/Fixtures/Fixtures16/Buyer.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Buyer.php rename to tests/Fixtures/Fixtures16/Buyer.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Ceo.php b/tests/Fixtures/Fixtures16/Ceo.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Ceo.php rename to tests/Fixtures/Fixtures16/Ceo.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Customer.php b/tests/Fixtures/Fixtures16/Customer.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Customer.php rename to tests/Fixtures/Fixtures16/Customer.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Employee.php b/tests/Fixtures/Fixtures16/Employee.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Employee.php rename to tests/Fixtures/Fixtures16/Employee.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Executive.php b/tests/Fixtures/Fixtures16/Executive.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Executive.php rename to tests/Fixtures/Fixtures16/Executive.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Executive2.php b/tests/Fixtures/Fixtures16/Executive2.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Executive2.php rename to tests/Fixtures/Fixtures16/Executive2.php diff --git a/tests/Annotated/Fixtures/Fixtures16/ExecutiveProxy.php b/tests/Fixtures/Fixtures16/ExecutiveProxy.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/ExecutiveProxy.php rename to tests/Fixtures/Fixtures16/ExecutiveProxy.php diff --git a/tests/Annotated/Fixtures/Fixtures16/ExternalSupplier.php b/tests/Fixtures/Fixtures16/ExternalSupplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/ExternalSupplier.php rename to tests/Fixtures/Fixtures16/ExternalSupplier.php diff --git a/tests/Annotated/Fixtures/Fixtures16/ExtraColumns.php b/tests/Fixtures/Fixtures16/ExtraColumns.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/ExtraColumns.php rename to tests/Fixtures/Fixtures16/ExtraColumns.php diff --git a/tests/Annotated/Fixtures/Fixtures16/FooColumns.php b/tests/Fixtures/Fixtures16/FooColumns.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/FooColumns.php rename to tests/Fixtures/Fixtures16/FooColumns.php diff --git a/tests/Annotated/Fixtures/Fixtures16/LocalSupplier.php b/tests/Fixtures/Fixtures16/LocalSupplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/LocalSupplier.php rename to tests/Fixtures/Fixtures16/LocalSupplier.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Person.php b/tests/Fixtures/Fixtures16/Person.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Person.php rename to tests/Fixtures/Fixtures16/Person.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Supplier.php b/tests/Fixtures/Fixtures16/Supplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Supplier.php rename to tests/Fixtures/Fixtures16/Supplier.php diff --git a/tests/Annotated/Fixtures/Fixtures16/Tool.php b/tests/Fixtures/Fixtures16/Tool.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures16/Tool.php rename to tests/Fixtures/Fixtures16/Tool.php diff --git a/tests/Annotated/Fixtures/Fixtures17/MapperSegmentSchemaModifier.php b/tests/Fixtures/Fixtures17/MapperSegmentSchemaModifier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures17/MapperSegmentSchemaModifier.php rename to tests/Fixtures/Fixtures17/MapperSegmentSchemaModifier.php diff --git a/tests/Annotated/Fixtures/Fixtures17/ParentSegmentSchemaModifier.php b/tests/Fixtures/Fixtures17/ParentSegmentSchemaModifier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures17/ParentSegmentSchemaModifier.php rename to tests/Fixtures/Fixtures17/ParentSegmentSchemaModifier.php diff --git a/tests/Annotated/Fixtures/Fixtures17/Post.php b/tests/Fixtures/Fixtures17/Post.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures17/Post.php rename to tests/Fixtures/Fixtures17/Post.php diff --git a/tests/Annotated/Fixtures/Fixtures18/Booking.php b/tests/Fixtures/Fixtures18/Booking.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures18/Booking.php rename to tests/Fixtures/Fixtures18/Booking.php diff --git a/tests/Annotated/Fixtures/Fixtures18/Pivot.php b/tests/Fixtures/Fixtures18/Pivot.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures18/Pivot.php rename to tests/Fixtures/Fixtures18/Pivot.php diff --git a/tests/Annotated/Fixtures/Fixtures18/Reservation.php b/tests/Fixtures/Fixtures18/Reservation.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures18/Reservation.php rename to tests/Fixtures/Fixtures18/Reservation.php diff --git a/tests/Annotated/Fixtures/Fixtures18/Segment.php b/tests/Fixtures/Fixtures18/Segment.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures18/Segment.php rename to tests/Fixtures/Fixtures18/Segment.php diff --git a/tests/Annotated/Fixtures/Fixtures19/BackedEnum.php b/tests/Fixtures/Fixtures19/BackedEnum.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures19/BackedEnum.php rename to tests/Fixtures/Fixtures19/BackedEnum.php diff --git a/tests/Annotated/Fixtures/Fixtures19/BackedEnumWrapper.php b/tests/Fixtures/Fixtures19/BackedEnumWrapper.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures19/BackedEnumWrapper.php rename to tests/Fixtures/Fixtures19/BackedEnumWrapper.php diff --git a/tests/Annotated/Fixtures/Fixtures19/Booking.php b/tests/Fixtures/Fixtures19/Booking.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures19/Booking.php rename to tests/Fixtures/Fixtures19/Booking.php diff --git a/tests/Annotated/Fixtures/Fixtures2/Complete.php b/tests/Fixtures/Fixtures2/Complete.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures2/Complete.php rename to tests/Fixtures/Fixtures2/Complete.php diff --git a/tests/Annotated/Fixtures/Fixtures2/Mark.php b/tests/Fixtures/Fixtures2/Mark.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures2/Mark.php rename to tests/Fixtures/Fixtures2/Mark.php diff --git a/tests/Annotated/Fixtures/Fixtures2/MarkedInterface.php b/tests/Fixtures/Fixtures2/MarkedInterface.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures2/MarkedInterface.php rename to tests/Fixtures/Fixtures2/MarkedInterface.php diff --git a/tests/Annotated/Fixtures/Fixtures2/Simple.php b/tests/Fixtures/Fixtures2/Simple.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures2/Simple.php rename to tests/Fixtures/Fixtures2/Simple.php diff --git a/tests/Annotated/Fixtures/Fixtures2/User.php b/tests/Fixtures/Fixtures2/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures2/User.php rename to tests/Fixtures/Fixtures2/User.php diff --git a/tests/Annotated/Fixtures/Fixtures20/Buyer.php b/tests/Fixtures/Fixtures20/Buyer.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures20/Buyer.php rename to tests/Fixtures/Fixtures20/Buyer.php diff --git a/tests/Annotated/Fixtures/Fixtures20/Ceo.php b/tests/Fixtures/Fixtures20/Ceo.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures20/Ceo.php rename to tests/Fixtures/Fixtures20/Ceo.php diff --git a/tests/Annotated/Fixtures/Fixtures20/Customer.php b/tests/Fixtures/Fixtures20/Customer.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures20/Customer.php rename to tests/Fixtures/Fixtures20/Customer.php diff --git a/tests/Annotated/Fixtures/Fixtures20/Employee.php b/tests/Fixtures/Fixtures20/Employee.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures20/Employee.php rename to tests/Fixtures/Fixtures20/Employee.php diff --git a/tests/Annotated/Fixtures/Fixtures20/Person.php b/tests/Fixtures/Fixtures20/Person.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures20/Person.php rename to tests/Fixtures/Fixtures20/Person.php diff --git a/tests/Annotated/Fixtures/Fixtures21/Buyer.php b/tests/Fixtures/Fixtures21/Buyer.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures21/Buyer.php rename to tests/Fixtures/Fixtures21/Buyer.php diff --git a/tests/Annotated/Fixtures/Fixtures21/Employee.php b/tests/Fixtures/Fixtures21/Employee.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures21/Employee.php rename to tests/Fixtures/Fixtures21/Employee.php diff --git a/tests/Annotated/Fixtures/Fixtures21/Executive.php b/tests/Fixtures/Fixtures21/Executive.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures21/Executive.php rename to tests/Fixtures/Fixtures21/Executive.php diff --git a/tests/Annotated/Fixtures/Fixtures21/Person.php b/tests/Fixtures/Fixtures21/Person.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures21/Person.php rename to tests/Fixtures/Fixtures21/Person.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Annotated/LocalManager.php b/tests/Fixtures/Fixtures22/Annotated/LocalManager.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Annotated/LocalManager.php rename to tests/Fixtures/Fixtures22/Annotated/LocalManager.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Annotated/LocalSupplier.php b/tests/Fixtures/Fixtures22/Annotated/LocalSupplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Annotated/LocalSupplier.php rename to tests/Fixtures/Fixtures22/Annotated/LocalSupplier.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Annotated/Person.php b/tests/Fixtures/Fixtures22/Annotated/Person.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Annotated/Person.php rename to tests/Fixtures/Fixtures22/Annotated/Person.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Annotated/Supplier.php b/tests/Fixtures/Fixtures22/Annotated/Supplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Annotated/Supplier.php rename to tests/Fixtures/Fixtures22/Annotated/Supplier.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Attributed/LocalManager.php b/tests/Fixtures/Fixtures22/Attributed/LocalManager.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Attributed/LocalManager.php rename to tests/Fixtures/Fixtures22/Attributed/LocalManager.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Attributed/LocalSupplier.php b/tests/Fixtures/Fixtures22/Attributed/LocalSupplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Attributed/LocalSupplier.php rename to tests/Fixtures/Fixtures22/Attributed/LocalSupplier.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Attributed/Person.php b/tests/Fixtures/Fixtures22/Attributed/Person.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Attributed/Person.php rename to tests/Fixtures/Fixtures22/Attributed/Person.php diff --git a/tests/Annotated/Fixtures/Fixtures22/Attributed/Supplier.php b/tests/Fixtures/Fixtures22/Attributed/Supplier.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures22/Attributed/Supplier.php rename to tests/Fixtures/Fixtures22/Attributed/Supplier.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/BaseEvent.php b/tests/Fixtures/Fixtures23/STIWithClassColumn/BaseEvent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/BaseEvent.php rename to tests/Fixtures/Fixtures23/STIWithClassColumn/BaseEvent.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/Comment.php b/tests/Fixtures/Fixtures23/STIWithClassColumn/Comment.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/Comment.php rename to tests/Fixtures/Fixtures23/STIWithClassColumn/Comment.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/CommentCreated.php b/tests/Fixtures/Fixtures23/STIWithClassColumn/CommentCreated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/CommentCreated.php rename to tests/Fixtures/Fixtures23/STIWithClassColumn/CommentCreated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/CommentUpdated.php b/tests/Fixtures/Fixtures23/STIWithClassColumn/CommentUpdated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/CommentUpdated.php rename to tests/Fixtures/Fixtures23/STIWithClassColumn/CommentUpdated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/EventEmitterInterface.php b/tests/Fixtures/Fixtures23/STIWithClassColumn/EventEmitterInterface.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithClassColumn/EventEmitterInterface.php rename to tests/Fixtures/Fixtures23/STIWithClassColumn/EventEmitterInterface.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/BaseEvent.php b/tests/Fixtures/Fixtures23/STIWithEntityColumn/BaseEvent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/BaseEvent.php rename to tests/Fixtures/Fixtures23/STIWithEntityColumn/BaseEvent.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/Comment.php b/tests/Fixtures/Fixtures23/STIWithEntityColumn/Comment.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/Comment.php rename to tests/Fixtures/Fixtures23/STIWithEntityColumn/Comment.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/CommentCreated.php b/tests/Fixtures/Fixtures23/STIWithEntityColumn/CommentCreated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/CommentCreated.php rename to tests/Fixtures/Fixtures23/STIWithEntityColumn/CommentCreated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/CommentUpdated.php b/tests/Fixtures/Fixtures23/STIWithEntityColumn/CommentUpdated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/CommentUpdated.php rename to tests/Fixtures/Fixtures23/STIWithEntityColumn/CommentUpdated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/EventEmitterInterface.php b/tests/Fixtures/Fixtures23/STIWithEntityColumn/EventEmitterInterface.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithEntityColumn/EventEmitterInterface.php rename to tests/Fixtures/Fixtures23/STIWithEntityColumn/EventEmitterInterface.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/BaseEvent.php b/tests/Fixtures/Fixtures23/STIWithPropertyColumn/BaseEvent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/BaseEvent.php rename to tests/Fixtures/Fixtures23/STIWithPropertyColumn/BaseEvent.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/Comment.php b/tests/Fixtures/Fixtures23/STIWithPropertyColumn/Comment.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/Comment.php rename to tests/Fixtures/Fixtures23/STIWithPropertyColumn/Comment.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/CommentCreated.php b/tests/Fixtures/Fixtures23/STIWithPropertyColumn/CommentCreated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/CommentCreated.php rename to tests/Fixtures/Fixtures23/STIWithPropertyColumn/CommentCreated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/CommentUpdated.php b/tests/Fixtures/Fixtures23/STIWithPropertyColumn/CommentUpdated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/CommentUpdated.php rename to tests/Fixtures/Fixtures23/STIWithPropertyColumn/CommentUpdated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/EventEmitterInterface.php b/tests/Fixtures/Fixtures23/STIWithPropertyColumn/EventEmitterInterface.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithPropertyColumn/EventEmitterInterface.php rename to tests/Fixtures/Fixtures23/STIWithPropertyColumn/EventEmitterInterface.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/BaseEvent.php b/tests/Fixtures/Fixtures23/STIWithTableColumn/BaseEvent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/BaseEvent.php rename to tests/Fixtures/Fixtures23/STIWithTableColumn/BaseEvent.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/Comment.php b/tests/Fixtures/Fixtures23/STIWithTableColumn/Comment.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/Comment.php rename to tests/Fixtures/Fixtures23/STIWithTableColumn/Comment.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/CommentCreated.php b/tests/Fixtures/Fixtures23/STIWithTableColumn/CommentCreated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/CommentCreated.php rename to tests/Fixtures/Fixtures23/STIWithTableColumn/CommentCreated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/CommentUpdated.php b/tests/Fixtures/Fixtures23/STIWithTableColumn/CommentUpdated.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/CommentUpdated.php rename to tests/Fixtures/Fixtures23/STIWithTableColumn/CommentUpdated.php diff --git a/tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/EventEmitterInterface.php b/tests/Fixtures/Fixtures23/STIWithTableColumn/EventEmitterInterface.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures23/STIWithTableColumn/EventEmitterInterface.php rename to tests/Fixtures/Fixtures23/STIWithTableColumn/EventEmitterInterface.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Class/DatabaseField/DatabaseField.php b/tests/Fixtures/Fixtures24/Class/DatabaseField/DatabaseField.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Class/DatabaseField/DatabaseField.php rename to tests/Fixtures/Fixtures24/Class/DatabaseField/DatabaseField.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Class/DatabaseField/Target.php b/tests/Fixtures/Fixtures24/Class/DatabaseField/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Class/DatabaseField/Target.php rename to tests/Fixtures/Fixtures24/Class/DatabaseField/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Class/PrimaryKey/PrimaryKey.php b/tests/Fixtures/Fixtures24/Class/PrimaryKey/PrimaryKey.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Class/PrimaryKey/PrimaryKey.php rename to tests/Fixtures/Fixtures24/Class/PrimaryKey/PrimaryKey.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Class/PrimaryKey/Target.php b/tests/Fixtures/Fixtures24/Class/PrimaryKey/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Class/PrimaryKey/Target.php rename to tests/Fixtures/Fixtures24/Class/PrimaryKey/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Class/PropertyName/PropertyName.php b/tests/Fixtures/Fixtures24/Class/PropertyName/PropertyName.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Class/PropertyName/PropertyName.php rename to tests/Fixtures/Fixtures24/Class/PropertyName/PropertyName.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Class/PropertyName/Target.php b/tests/Fixtures/Fixtures24/Class/PropertyName/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Class/PropertyName/Target.php rename to tests/Fixtures/Fixtures24/Class/PropertyName/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Entity/DatabaseField/DatabaseField.php b/tests/Fixtures/Fixtures24/Entity/DatabaseField/DatabaseField.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Entity/DatabaseField/DatabaseField.php rename to tests/Fixtures/Fixtures24/Entity/DatabaseField/DatabaseField.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Entity/DatabaseField/Target.php b/tests/Fixtures/Fixtures24/Entity/DatabaseField/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Entity/DatabaseField/Target.php rename to tests/Fixtures/Fixtures24/Entity/DatabaseField/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Entity/PrimaryKey/PrimaryKey.php b/tests/Fixtures/Fixtures24/Entity/PrimaryKey/PrimaryKey.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Entity/PrimaryKey/PrimaryKey.php rename to tests/Fixtures/Fixtures24/Entity/PrimaryKey/PrimaryKey.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Entity/PrimaryKey/Target.php b/tests/Fixtures/Fixtures24/Entity/PrimaryKey/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Entity/PrimaryKey/Target.php rename to tests/Fixtures/Fixtures24/Entity/PrimaryKey/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Entity/PropertyName/PropertyName.php b/tests/Fixtures/Fixtures24/Entity/PropertyName/PropertyName.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Entity/PropertyName/PropertyName.php rename to tests/Fixtures/Fixtures24/Entity/PropertyName/PropertyName.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Entity/PropertyName/Target.php b/tests/Fixtures/Fixtures24/Entity/PropertyName/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Entity/PropertyName/Target.php rename to tests/Fixtures/Fixtures24/Entity/PropertyName/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Property/DatabaseField/DatabaseField.php b/tests/Fixtures/Fixtures24/Property/DatabaseField/DatabaseField.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Property/DatabaseField/DatabaseField.php rename to tests/Fixtures/Fixtures24/Property/DatabaseField/DatabaseField.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Property/DatabaseField/Target.php b/tests/Fixtures/Fixtures24/Property/DatabaseField/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Property/DatabaseField/Target.php rename to tests/Fixtures/Fixtures24/Property/DatabaseField/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Property/PrimaryKey/PrimaryKey.php b/tests/Fixtures/Fixtures24/Property/PrimaryKey/PrimaryKey.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Property/PrimaryKey/PrimaryKey.php rename to tests/Fixtures/Fixtures24/Property/PrimaryKey/PrimaryKey.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Property/PrimaryKey/Target.php b/tests/Fixtures/Fixtures24/Property/PrimaryKey/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Property/PrimaryKey/Target.php rename to tests/Fixtures/Fixtures24/Property/PrimaryKey/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Property/PropertyName/PropertyName.php b/tests/Fixtures/Fixtures24/Property/PropertyName/PropertyName.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Property/PropertyName/PropertyName.php rename to tests/Fixtures/Fixtures24/Property/PropertyName/PropertyName.php diff --git a/tests/Annotated/Fixtures/Fixtures24/Property/PropertyName/Target.php b/tests/Fixtures/Fixtures24/Property/PropertyName/Target.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures24/Property/PropertyName/Target.php rename to tests/Fixtures/Fixtures24/Property/PropertyName/Target.php diff --git a/tests/Annotated/Fixtures/Fixtures25/PostgreSQL/WithGeneratedSerial.php b/tests/Fixtures/Fixtures25/PostgreSQL/WithGeneratedSerial.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures25/PostgreSQL/WithGeneratedSerial.php rename to tests/Fixtures/Fixtures25/PostgreSQL/WithGeneratedSerial.php diff --git a/tests/Annotated/Fixtures/Fixtures25/WithGeneratedFields.php b/tests/Fixtures/Fixtures25/WithGeneratedFields.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures25/WithGeneratedFields.php rename to tests/Fixtures/Fixtures25/WithGeneratedFields.php diff --git a/tests/Annotated/Fixtures/Fixtures26/Address.php b/tests/Fixtures/Fixtures26/Address.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures26/Address.php rename to tests/Fixtures/Fixtures26/Address.php diff --git a/tests/Annotated/Fixtures/Fixtures26/City.php b/tests/Fixtures/Fixtures26/City.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures26/City.php rename to tests/Fixtures/Fixtures26/City.php diff --git a/tests/Annotated/Fixtures/Fixtures26/CityTypecast.php b/tests/Fixtures/Fixtures26/CityTypecast.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures26/CityTypecast.php rename to tests/Fixtures/Fixtures26/CityTypecast.php diff --git a/tests/Annotated/Fixtures/Fixtures26/User.php b/tests/Fixtures/Fixtures26/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures26/User.php rename to tests/Fixtures/Fixtures26/User.php diff --git a/tests/Annotated/Fixtures/Fixtures27/BtJoined.php b/tests/Fixtures/Fixtures27/BtJoined.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/BtJoined.php rename to tests/Fixtures/Fixtures27/BtJoined.php diff --git a/tests/Annotated/Fixtures/Fixtures27/BtParent.php b/tests/Fixtures/Fixtures27/BtParent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/BtParent.php rename to tests/Fixtures/Fixtures27/BtParent.php diff --git a/tests/Annotated/Fixtures/Fixtures27/BtTarget.php b/tests/Fixtures/Fixtures27/BtTarget.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/BtTarget.php rename to tests/Fixtures/Fixtures27/BtTarget.php diff --git a/tests/Annotated/Fixtures/Fixtures27/JgLeaf.php b/tests/Fixtures/Fixtures27/JgLeaf.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/JgLeaf.php rename to tests/Fixtures/Fixtures27/JgLeaf.php diff --git a/tests/Annotated/Fixtures/Fixtures27/JgMid.php b/tests/Fixtures/Fixtures27/JgMid.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/JgMid.php rename to tests/Fixtures/Fixtures27/JgMid.php diff --git a/tests/Annotated/Fixtures/Fixtures27/JgParent.php b/tests/Fixtures/Fixtures27/JgParent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/JgParent.php rename to tests/Fixtures/Fixtures27/JgParent.php diff --git a/tests/Annotated/Fixtures/Fixtures27/JgTarget.php b/tests/Fixtures/Fixtures27/JgTarget.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/JgTarget.php rename to tests/Fixtures/Fixtures27/JgTarget.php diff --git a/tests/Annotated/Fixtures/Fixtures27/SoParent.php b/tests/Fixtures/Fixtures27/SoParent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/SoParent.php rename to tests/Fixtures/Fixtures27/SoParent.php diff --git a/tests/Annotated/Fixtures/Fixtures27/SoSeparate.php b/tests/Fixtures/Fixtures27/SoSeparate.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/SoSeparate.php rename to tests/Fixtures/Fixtures27/SoSeparate.php diff --git a/tests/Annotated/Fixtures/Fixtures27/SoSti.php b/tests/Fixtures/Fixtures27/SoSti.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/SoSti.php rename to tests/Fixtures/Fixtures27/SoSti.php diff --git a/tests/Annotated/Fixtures/Fixtures27/SoTarget.php b/tests/Fixtures/Fixtures27/SoTarget.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/SoTarget.php rename to tests/Fixtures/Fixtures27/SoTarget.php diff --git a/tests/Annotated/Fixtures/Fixtures27/StChild.php b/tests/Fixtures/Fixtures27/StChild.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/StChild.php rename to tests/Fixtures/Fixtures27/StChild.php diff --git a/tests/Annotated/Fixtures/Fixtures27/StParent.php b/tests/Fixtures/Fixtures27/StParent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/StParent.php rename to tests/Fixtures/Fixtures27/StParent.php diff --git a/tests/Annotated/Fixtures/Fixtures27/StTarget.php b/tests/Fixtures/Fixtures27/StTarget.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/StTarget.php rename to tests/Fixtures/Fixtures27/StTarget.php diff --git a/tests/Annotated/Fixtures/Fixtures27/TrJti.php b/tests/Fixtures/Fixtures27/TrJti.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/TrJti.php rename to tests/Fixtures/Fixtures27/TrJti.php diff --git a/tests/Annotated/Fixtures/Fixtures27/TrParent.php b/tests/Fixtures/Fixtures27/TrParent.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/TrParent.php rename to tests/Fixtures/Fixtures27/TrParent.php diff --git a/tests/Annotated/Fixtures/Fixtures27/TrRelTrait.php b/tests/Fixtures/Fixtures27/TrRelTrait.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/TrRelTrait.php rename to tests/Fixtures/Fixtures27/TrRelTrait.php diff --git a/tests/Annotated/Fixtures/Fixtures27/TrTarget.php b/tests/Fixtures/Fixtures27/TrTarget.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures27/TrTarget.php rename to tests/Fixtures/Fixtures27/TrTarget.php diff --git a/tests/Annotated/Fixtures/Fixtures28/Event.php b/tests/Fixtures/Fixtures28/Event.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures28/Event.php rename to tests/Fixtures/Fixtures28/Event.php diff --git a/tests/Annotated/Fixtures/Fixtures3/User.php b/tests/Fixtures/Fixtures3/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures3/User.php rename to tests/Fixtures/Fixtures3/User.php diff --git a/tests/Annotated/Fixtures/Fixtures4/User.php b/tests/Fixtures/Fixtures4/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures4/User.php rename to tests/Fixtures/Fixtures4/User.php diff --git a/tests/Annotated/Fixtures/Fixtures5/Simple.php b/tests/Fixtures/Fixtures5/Simple.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures5/Simple.php rename to tests/Fixtures/Fixtures5/Simple.php diff --git a/tests/Annotated/Fixtures/Fixtures5/User.php b/tests/Fixtures/Fixtures5/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures5/User.php rename to tests/Fixtures/Fixtures5/User.php diff --git a/tests/Annotated/Fixtures/Fixtures6/Address.php b/tests/Fixtures/Fixtures6/Address.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures6/Address.php rename to tests/Fixtures/Fixtures6/Address.php diff --git a/tests/Annotated/Fixtures/Fixtures6/User.php b/tests/Fixtures/Fixtures6/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures6/User.php rename to tests/Fixtures/Fixtures6/User.php diff --git a/tests/Annotated/Fixtures/Fixtures7/Address.php b/tests/Fixtures/Fixtures7/Address.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures7/Address.php rename to tests/Fixtures/Fixtures7/Address.php diff --git a/tests/Annotated/Fixtures/Fixtures7/User.php b/tests/Fixtures/Fixtures7/User.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures7/User.php rename to tests/Fixtures/Fixtures7/User.php diff --git a/tests/Annotated/Fixtures/Fixtures8/Article.php b/tests/Fixtures/Fixtures8/Article.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures8/Article.php rename to tests/Fixtures/Fixtures8/Article.php diff --git a/tests/Annotated/Fixtures/Fixtures8/Post.php b/tests/Fixtures/Fixtures8/Post.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures8/Post.php rename to tests/Fixtures/Fixtures8/Post.php diff --git a/tests/Annotated/Fixtures/Fixtures8/Some.php b/tests/Fixtures/Fixtures8/Some.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures8/Some.php rename to tests/Fixtures/Fixtures8/Some.php diff --git a/tests/Annotated/Fixtures/Fixtures9/OrderedIdx.php b/tests/Fixtures/Fixtures9/OrderedIdx.php similarity index 100% rename from tests/Annotated/Fixtures/Fixtures9/OrderedIdx.php rename to tests/Fixtures/Fixtures9/OrderedIdx.php diff --git a/tests/Annotated/Fixtures/RefersToMorphed/Comment.php b/tests/Fixtures/RefersToMorphed/Comment.php similarity index 100% rename from tests/Annotated/Fixtures/RefersToMorphed/Comment.php rename to tests/Fixtures/RefersToMorphed/Comment.php diff --git a/tests/Annotated/Fixtures/RefersToMorphed/MorphedParentInterface.php b/tests/Fixtures/RefersToMorphed/MorphedParentInterface.php similarity index 100% rename from tests/Annotated/Fixtures/RefersToMorphed/MorphedParentInterface.php rename to tests/Fixtures/RefersToMorphed/MorphedParentInterface.php diff --git a/tests/Annotated/Fixtures/RefersToMorphed/Post.php b/tests/Fixtures/RefersToMorphed/Post.php similarity index 100% rename from tests/Annotated/Fixtures/RefersToMorphed/Post.php rename to tests/Fixtures/RefersToMorphed/Post.php diff --git a/tests/Annotated/Unit/Attribute/ColumnTest.php b/tests/Unit/Attribute/ColumnTest.php similarity index 67% rename from tests/Annotated/Unit/Attribute/ColumnTest.php rename to tests/Unit/Attribute/ColumnTest.php index 897d984f..1f1ec71b 100644 --- a/tests/Annotated/Unit/Attribute/ColumnTest.php +++ b/tests/Unit/Attribute/ColumnTest.php @@ -6,9 +6,11 @@ use Cycle\Annotated\Annotation\Column; use Cycle\Annotated\Tests\Unit\Attribute\SingleTable\StringEnum; -use PHPUnit\Framework\TestCase; +use Testo\Assert; +use Testo\Test; -class ColumnTest extends TestCase +#[Test] +final class ColumnTest { public const ENUM_VALUE_A = 'a'; public const ENUM_VALUE_B = 'b'; @@ -64,95 +66,95 @@ public function testOneAttribute(): void { $column = $this->getColumn('column1'); - $this->assertSame(['unsigned' => true], $column->getAttributes()); + Assert::same($column->getAttributes(), ['unsigned' => true]); } public function testTwoAttributes(): void { $column = $this->getColumn('column2'); - $this->assertSame(['unsigned' => true, 'zerofill' => true], $column->getAttributes()); + Assert::same($column->getAttributes(), ['unsigned' => true, 'zerofill' => true]); } public function testCustomSizeAttribute(): void { $column = $this->getColumn('column3'); - $this->assertSame(['size' => 128], $column->getAttributes()); + Assert::same($column->getAttributes(), ['size' => 128]); } public function testDefaultReadonlySchema(): void { $column = $this->getColumn('column1'); - $this->assertFalse($column->isReadonlySchema()); + Assert::false($column->isReadonlySchema()); } public function testReadonlySchema(): void { $column = $this->getColumn('column4'); - $this->assertTrue($column->isReadonlySchema()); + Assert::true($column->isReadonlySchema()); } public function testEnumTypeString(): void { $column = $this->getColumn('column5'); - $this->assertSame('enum(a,b)', $column->getType()); + Assert::same($column->getType(), 'enum(a,b)'); } public function testEnumTypeArray(): void { $column = $this->getColumn('column6'); - $this->assertSame('enum(a,b)', $column->getType()); - $this->assertSame('a', $column->getDefault()); - $this->assertArrayNotHasKey('values', $column->getAttributes()); + Assert::same($column->getType(), 'enum(a,b)'); + Assert::same($column->getDefault(), 'a'); + Assert::array($column->getAttributes())->doesNotHaveKeys('values'); } public function testEnumTypeBackedEnum(): void { $column = $this->getColumn('column7'); - $this->assertSame('enum(a,b)', $column->getType()); - $this->assertSame('a', $column->getDefault()); - $this->assertArrayNotHasKey('values', $column->getAttributes()); + Assert::same($column->getType(), 'enum(a,b)'); + Assert::same($column->getDefault(), 'a'); + Assert::array($column->getAttributes())->doesNotHaveKeys('values'); } public function testEnumTypeArrayBackedEnum(): void { $column = $this->getColumn('column8'); - $this->assertSame('enum(a,b)', $column->getType()); - $this->assertSame('a', $column->getDefault()); - $this->assertArrayNotHasKey('values', $column->getAttributes()); + Assert::same($column->getType(), 'enum(a,b)'); + Assert::same($column->getDefault(), 'a'); + Assert::array($column->getAttributes())->doesNotHaveKeys('values'); } public function testEnumTypeBackedEnumAsDefault(): void { $column = $this->getColumn('column10'); - $this->assertSame('enum(a,b)', $column->getType()); - $this->assertSame('a', $column->getDefault()); - $this->assertArrayNotHasKey('values', $column->getAttributes()); + Assert::same($column->getType(), 'enum(a,b)'); + Assert::same($column->getDefault(), 'a'); + Assert::array($column->getAttributes())->doesNotHaveKeys('values'); } public function testCharsetAndCollationAttributes(): void { $column = $this->getColumn('column9'); - $this->assertSame('string', $column->getType()); - $this->assertSame([ + Assert::same($column->getType(), 'string'); + Assert::same($column->getAttributes(), [ 'length' => 255, 'charset' => 'ascii', 'collation' => 'ascii_bin', - ], $column->getAttributes()); + ]); } private function getColumn(string $field): Column { - $ref = new \ReflectionClass(static::class); + $ref = new \ReflectionClass(self::class); return $ref->getProperty($field)->getAttributes(Column::class)[0]->newInstance(); } } diff --git a/tests/Annotated/Unit/Attribute/SingleTable/IntegerEnum.php b/tests/Unit/Attribute/SingleTable/IntegerEnum.php similarity index 100% rename from tests/Annotated/Unit/Attribute/SingleTable/IntegerEnum.php rename to tests/Unit/Attribute/SingleTable/IntegerEnum.php diff --git a/tests/Annotated/Unit/Attribute/SingleTable/SingleTableTest.php b/tests/Unit/Attribute/SingleTable/SingleTableTest.php similarity index 76% rename from tests/Annotated/Unit/Attribute/SingleTable/SingleTableTest.php rename to tests/Unit/Attribute/SingleTable/SingleTableTest.php index 63588803..a7208651 100644 --- a/tests/Annotated/Unit/Attribute/SingleTable/SingleTableTest.php +++ b/tests/Unit/Attribute/SingleTable/SingleTableTest.php @@ -5,10 +5,12 @@ namespace Cycle\Annotated\Tests\Unit\Attribute\SingleTable; use Cycle\Annotated\Annotation\Inheritance\SingleTable; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\TestCase; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -final class SingleTableTest extends TestCase +#[Test] +final class SingleTableTest { public static function dataBase(): iterable { @@ -26,6 +28,6 @@ public function testBase1(?string $expected, mixed $value): void { $attribute = new SingleTable($value); - $this->assertSame($expected, $attribute->getValue()); + Assert::same($attribute->getValue(), $expected); } } diff --git a/tests/Annotated/Unit/Attribute/SingleTable/StringEnum.php b/tests/Unit/Attribute/SingleTable/StringEnum.php similarity index 100% rename from tests/Annotated/Unit/Attribute/SingleTable/StringEnum.php rename to tests/Unit/Attribute/SingleTable/StringEnum.php diff --git a/tests/Annotated/Unit/Attribute/SingleTable/StringableObject.php b/tests/Unit/Attribute/SingleTable/StringableObject.php similarity index 100% rename from tests/Annotated/Unit/Attribute/SingleTable/StringableObject.php rename to tests/Unit/Attribute/SingleTable/StringableObject.php diff --git a/tests/Annotated/Unit/Locator/TokenizerEmbeddingLocatorTest.php b/tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php similarity index 71% rename from tests/Annotated/Unit/Locator/TokenizerEmbeddingLocatorTest.php rename to tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php index 59132fa3..3b6e5240 100644 --- a/tests/Annotated/Unit/Locator/TokenizerEmbeddingLocatorTest.php +++ b/tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php @@ -9,11 +9,13 @@ use Cycle\Annotated\Locator\TokenizerEmbeddingLocator; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Child; use Cycle\Annotated\Tests\Fixtures\Fixtures7\Address; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\TestCase; -use Spiral\Tokenizer\ClassesInterface; +use Cycle\Testing\ORM\Schema\ClassList; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -final class TokenizerEmbeddingLocatorTest extends TestCase +#[Test] +final class TokenizerEmbeddingLocatorTest { public static function classesDataProvider(): \Traversable { @@ -36,11 +38,10 @@ public static function classesDataProvider(): \Traversable #[DataProvider('classesDataProvider')] public function testGetEmbeddings(array $expected, array $classes): void { - $mock = $this->createMock(ClassesInterface::class); - $mock->method('getClasses')->willReturn($classes); + $source = new ClassList(...\array_keys($classes)); - $locator = new TokenizerEmbeddingLocator($mock); + $locator = new TokenizerEmbeddingLocator($source); - $this->assertEquals($expected, $locator->getEmbeddings()); + Assert::equals($locator->getEmbeddings(), $expected); } } diff --git a/tests/Annotated/Unit/Locator/TokenizerEntityLocatorTest.php b/tests/Unit/Locator/TokenizerEntityLocatorTest.php similarity index 77% rename from tests/Annotated/Unit/Locator/TokenizerEntityLocatorTest.php rename to tests/Unit/Locator/TokenizerEntityLocatorTest.php index 6c341b1f..d2f9cfe7 100644 --- a/tests/Annotated/Unit/Locator/TokenizerEntityLocatorTest.php +++ b/tests/Unit/Locator/TokenizerEntityLocatorTest.php @@ -12,11 +12,13 @@ use Cycle\Annotated\Tests\Fixtures\Fixtures1\Typecast\Typecaster; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Typecast\UuidTypecaster; use Cycle\Annotated\Tests\Fixtures\Fixtures1\WithTable; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\TestCase; -use Spiral\Tokenizer\ClassesInterface; +use Cycle\Testing\ORM\Schema\ClassList; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -final class TokenizerEntityLocatorTest extends TestCase +#[Test] +final class TokenizerEntityLocatorTest { public static function classesDataProvider(): \Traversable { @@ -43,11 +45,10 @@ public static function classesDataProvider(): \Traversable #[DataProvider('classesDataProvider')] public function testGetEntities(array $expected, array $classes): void { - $mock = $this->createMock(ClassesInterface::class); - $mock->method('getClasses')->willReturn($classes); + $source = new ClassList(...\array_keys($classes)); - $locator = new TokenizerEntityLocator($mock); + $locator = new TokenizerEntityLocator($source); - $this->assertEquals($expected, $locator->getEntities()); + Assert::equals($locator->getEntities(), $expected); } } diff --git a/tests/Annotated/Unit/ReaderFactoryTest.php b/tests/Unit/ReaderFactoryTest.php similarity index 74% rename from tests/Annotated/Unit/ReaderFactoryTest.php rename to tests/Unit/ReaderFactoryTest.php index 826c1c2e..308898a2 100644 --- a/tests/Annotated/Unit/ReaderFactoryTest.php +++ b/tests/Unit/ReaderFactoryTest.php @@ -6,25 +6,27 @@ use Cycle\Annotated\ReaderFactory; use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; -use PHPUnit\Framework\TestCase; use Spiral\Attributes\AnnotationReader; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\Composite\MergeReader; +use Testo\Assert; +use Testo\Test; -class ReaderFactoryTest extends TestCase +#[Test] +final class ReaderFactoryTest { public function testCreateFromNull(): void { $reader = ReaderFactory::create(null); - $this->assertInstanceOf(AttributeReader::class, $reader); + Assert::instanceOf($reader, AttributeReader::class); } public function testCreateFromDoctrineReader(): void { $reader = ReaderFactory::create(new DoctrineAnnotationReader()); - $this->assertInstanceOf(AnnotationReader::class, $reader); + Assert::instanceOf($reader, AnnotationReader::class); } public function testCreateFromCustomReader(): void @@ -32,6 +34,6 @@ public function testCreateFromCustomReader(): void $mergeReader = new MergeReader([]); $reader = ReaderFactory::create($mergeReader); - $this->assertSame($mergeReader, $reader); + Assert::same($reader, $mergeReader); } } diff --git a/tests/Annotated/Unit/Utils/EntityUtilsTest.php b/tests/Unit/Utils/EntityUtilsTest.php similarity index 86% rename from tests/Annotated/Unit/Utils/EntityUtilsTest.php rename to tests/Unit/Utils/EntityUtilsTest.php index 07300cb4..c7cde20f 100644 --- a/tests/Annotated/Unit/Utils/EntityUtilsTest.php +++ b/tests/Unit/Utils/EntityUtilsTest.php @@ -7,13 +7,16 @@ use Cycle\Annotated\Exception\AnnotationException; use Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed\Person; use Cycle\Annotated\Utils\EntityUtils; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\TestCase; use Spiral\Attributes\AnnotationReader; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\ReaderInterface; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Expect; +use Testo\Test; -class EntityUtilsTest extends TestCase +#[Test] +final class EntityUtilsTest { public static function findParentDataProvider(): iterable { @@ -57,17 +60,14 @@ public function testFindParent( $actualParent = $entityUtils->findParent($child, $root); - $this->assertEquals($expectedParent, $actualParent); + Assert::equals($actualParent, $expectedParent); } public function testGetParentException(): void { $entityUtils = new EntityUtils(new AttributeReader()); - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage( - \sprintf('The parent class could not be found for the class `%s`.', Person::class), - ); + Expect::exception(AnnotationException::class)->withMessageContaining(\sprintf('The parent class could not be found for the class `%s`.', Person::class)); $entityUtils->getParent(Person::class); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index eb42c44b..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,60 +0,0 @@ - new Config\SQLiteDriverConfig( - queryCache: true, - ), - 'mysql' => new Config\MySQLDriverConfig( - connection: new Config\MySQL\TcpConnectionConfig( - database: 'spiral', - host: '127.0.0.1', - port: 13306, - user: 'root', - password: 'YourStrong!Passw0rd', - ), - queryCache: true, - ), - 'postgres' => new Config\PostgresDriverConfig( - connection: new Config\Postgres\TcpConnectionConfig( - database: 'spiral', - host: '127.0.0.1', - port: 15432, - user: 'postgres', - password: 'YourStrong!Passw0rd', - ), - schema: 'public', - queryCache: true, - ), - 'sqlserver' => new Config\SQLServerDriverConfig( - connection: new Config\SQLServer\TcpConnectionConfig( - database: 'tempdb', - host: '127.0.0.1', - port: 11433, - trustServerCertificate: true, - user: 'SA', - password: 'YourStrong!Passw0rd', - ), - queryCache: true, - ), -]; - -$db = getenv('DB') ?: null; -\Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase::$config = [ - 'debug' => false, - 'strict' => true, - 'benchmark' => false, -] + ( - $db === null - ? $drivers - : array_intersect_key($drivers, array_flip((array) $db)) -); diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml deleted file mode 100644 index 9c4b5111..00000000 --- a/tests/docker-compose.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: "3" - -services: - sqlserver: - image: mcr.microsoft.com/mssql/server:2019-latest - ports: - - "11433:1433" - environment: - SA_PASSWORD: "YourStrong!Passw0rd" - ACCEPT_EULA: "Y" - - mysql_latest: - image: mysql:8.0 - command: --default-authentication-plugin=mysql_native_password - ports: - - "13306:3306" - environment: - MYSQL_DATABASE: "spiral" - MYSQL_ROOT_PASSWORD: "YourStrong!Passw0rd" - MYSQL_ROOT_HOST: "%" - - postgres: - image: postgres:12 - ports: - - "15432:5432" - environment: - POSTGRES_DB: "spiral" - POSTGRES_USER: "postgres" - POSTGRES_PASSWORD: "YourStrong!Passw0rd" diff --git a/tests/fix-binlog.sh b/tests/fix-binlog.sh deleted file mode 100644 index 3a6dee32..00000000 --- a/tests/fix-binlog.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -ex -sed -i '/\[mysqld\]/a\ -binlog_format = MIXED' /etc/mysql/my.cnf -sudo service mysql restart \ No newline at end of file diff --git a/tests/generate.php b/tests/generate.php deleted file mode 100644 index 3558c773..00000000 --- a/tests/generate.php +++ /dev/null @@ -1,113 +0,0 @@ - [__DIR__ . '/Annotated/Functional/Driver/Common'], - 'exclude' => [], -])); - -$databases = [ - 'sqlite' => [ - 'namespace' => 'Cycle\Annotated\Tests\Functional\Driver\SQLite', - 'directory' => __DIR__ . '/Annotated/Functional/Driver/SQLite/', - ], - 'mysql' => [ - 'namespace' => 'Cycle\Annotated\Tests\Functional\Driver\MySQL', - 'directory' => __DIR__ . '/Annotated/Functional/Driver/MySQL/', - ], - 'postgres' => [ - 'namespace' => 'Cycle\Annotated\Tests\Functional\Driver\Postgres', - 'directory' => __DIR__ . '/Annotated/Functional/Driver/Postgres/', - ], - 'sqlserver' => [ - 'namespace' => 'Cycle\Annotated\Tests\Functional\Driver\SQLServer', - 'directory' => __DIR__ . '/Annotated/Functional/Driver/SQLServer/', - ], -]; - -echo "Generating test classes for all database types...\n"; - -$classes = $tokenizer->classLocator()->getClasses(\Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase::class); - -foreach ($classes as $baseClass) { - foreach ($baseClass->getMethods() as $method) { - if ($method->isAbstract()) { - echo "Skip class {$baseClass->getName()} with abstract methods.\n"; - continue 2; - } - } - - if ( - !$baseClass->isAbstract() - // Has abstract methods - || $baseClass->getName() == \Cycle\Annotated\Tests\Functional\Driver\Common\BaseTestCase::class - ) { - continue; - } - - echo "Found {$baseClass->getName()}\n"; - - $path = str_replace( - [str_replace('\\', '/', __DIR__), 'Annotated/Functional/Driver/Common/'], - '', - str_replace('\\', '/', \str_replace('TestCase', 'Test', $baseClass->getFileName())), - ); - - $path = ltrim($path, '/'); - - foreach ($databases as $driver => $details) { - $filename = sprintf('%s%s', $details['directory'], $path); - $dir = pathinfo($filename, PATHINFO_DIRNAME); - - $namespace = str_replace( - 'Cycle\\Annotated\\Tests\\Functional\\Driver\\Common', - $details['namespace'], - $baseClass->getNamespaceName(), - ); - - if (!is_dir($dir)) { - mkdir($dir, recursive: true); - } - - file_put_contents( - $filename, - sprintf( - <<getName(), - $driver, - \str_replace('TestCase', 'Test', $baseClass->getShortName()), - $baseClass->getShortName(), - $driver, - ), - ); - } -} diff --git a/tests/install-pgsql-10.sh b/tests/install-pgsql-10.sh deleted file mode 100644 index 2653213e..00000000 --- a/tests/install-pgsql-10.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -ex -# from Doctrine -sudo service postgresql stop -sudo apt-get remove -q 'postgresql-*' -sudo apt-get update -q -sudo apt-get install -q postgresql-10 postgresql-client-10 -sudo cp /etc/postgresql/{9.6,10}/main/pg_hba.conf -sudo service postgresql restart \ No newline at end of file diff --git a/tests/install-sqlsrv.sh b/tests/install-sqlsrv.sh deleted file mode 100644 index fd2d6871..00000000 --- a/tests/install-sqlsrv.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -ex -curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - -curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list -sudo apt-get update - -sudo ACCEPT_EULA=Y apt-get install -qy msodbcsql17 mssql-tools