From b4ce9413b729a92493e3cb7103e99d6e16a6eff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:00:39 +0100 Subject: [PATCH 01/23] Add tests --- .gitignore | 2 + composer.json | 24 +- composer.lock | 75 ++++- src/AbstractService.php | 2 +- src/ORMExtension.php | 6 +- tests/ORM/ModelEvent.php | 9 + tests/ORM/ModelParticipant.php | 12 + tests/ORM/ServiceEvent.php | 9 + tests/ORM/ServiceParticipant.php | 9 + tests/Tests/AbstractTestCase.php | 60 ++++ tests/Tests/ClassLoadTest.phpt | 26 ++ tests/Tests/ReferencedAccessTest.phpt | 45 +++ tests/Tests/ServiceOperationTest.phpt | 122 ++++++++ tests/Tests/TableSelectionTest.phpt | 60 ++++ tests/Tests/output/TableSelectionTest.actual | 290 ++++++++++++++++++ .../Tests/output/TableSelectionTest.expected | 290 ++++++++++++++++++ tests/config.local.neon.example | 4 + tests/config.neon | 12 + tests/php.ini | 26 ++ tests/resource/schema.sql | 21 ++ 20 files changed, 1095 insertions(+), 9 deletions(-) create mode 100644 tests/ORM/ModelEvent.php create mode 100644 tests/ORM/ModelParticipant.php create mode 100644 tests/ORM/ServiceEvent.php create mode 100644 tests/ORM/ServiceParticipant.php create mode 100644 tests/Tests/AbstractTestCase.php create mode 100644 tests/Tests/ClassLoadTest.phpt create mode 100644 tests/Tests/ReferencedAccessTest.phpt create mode 100644 tests/Tests/ServiceOperationTest.phpt create mode 100644 tests/Tests/TableSelectionTest.phpt create mode 100644 tests/Tests/output/TableSelectionTest.actual create mode 100644 tests/Tests/output/TableSelectionTest.expected create mode 100644 tests/config.local.neon.example create mode 100644 tests/config.neon create mode 100644 tests/php.ini create mode 100644 tests/resource/schema.sql diff --git a/.gitignore b/.gitignore index 57872d0..83d3e5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /vendor/ +/tests/config.local.neon +/tests/temp/ diff --git a/composer.json b/composer.json index e51a4c0..1578df6 100644 --- a/composer.json +++ b/composer.json @@ -6,9 +6,13 @@ "version": "0.1.3", "require": { "php": ">=7.4", - "nette/di": "^3.0.8", + "nette/di": "^3.0", "nette/database": "^3.1", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-gettext": "*" + }, + "require-dev": { + "nette/tester": "^2.4.0" }, "authors": [ { @@ -26,7 +30,21 @@ ], "autoload": { "psr-4": { - "Fykosak\\NetteORM\\": "src/" + "Fykosak\\NetteORM\\": "src/", + "Fykosak\\NetteORM\\Tests\\": "tests/" } + }, + "scripts": { + "clearCache": [ + "rm -r tests/temp/*" + ], + "test": [ + "@clearCache", + "vendor/bin/tester tests -p php -s -c tests/php.ini -j 1" + ], + "testCoverage": [ + "@clearCache", + "vendor/bin/tester tests -p php --coverage coverage.html --coverage-src src/ -s -c tests/php.ini -j 1" + ] } } diff --git a/composer.lock b/composer.lock index d5c1468..cd888f8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "78d84f024bba4e6b80abe56c253a257a", + "content-hash": "af1256a9f93963ed604f02c381e2935d", "packages": [ { "name": "nette/caching", @@ -608,7 +608,75 @@ "time": "2021-03-03T22:53:25+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "nette/tester", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/nette/tester.git", + "reference": "0988c33459b49bfd6c8d06e16f29de96eba341e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/tester/zipball/0988c33459b49bfd6c8d06e16f29de96eba341e7", + "reference": "0988c33459b49bfd6c8d06e16f29de96eba341e7", + "shasum": "" + }, + "require": { + "php": ">=7.2 <8.1" + }, + "require-dev": { + "ext-simplexml": "*", + "phpstan/phpstan": "^0.12" + }, + "bin": [ + "src/tester" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "Nette Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏", + "homepage": "https://tester.nette.org", + "keywords": [ + "Xdebug", + "assertions", + "clover", + "code coverage", + "nette", + "pcov", + "phpdbg", + "phpunit", + "testing", + "unit" + ], + "time": "2021-03-01T15:27:25+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], @@ -616,7 +684,8 @@ "prefer-lowest": false, "platform": { "php": ">=7.4", - "ext-pdo": "*" + "ext-pdo": "*", + "ext-gettext": "*" }, "platform-dev": [] } diff --git a/src/AbstractService.php b/src/AbstractService.php index 401918d..091877e 100644 --- a/src/AbstractService.php +++ b/src/AbstractService.php @@ -109,7 +109,7 @@ public function dispose(AbstractModel $model): void { } public function getTable(): TypedTableSelection { - return new TypedTableSelection($this->getModelClassName(), $this->tableName, $this->explorer, $this->conventions); + return new TypedTableSelection($this->getModelClassName(), $this->tableName, $this->explorer, $this->explorer->getConventions()); } public function store(?AbstractModel $model, array $data): AbstractModel { diff --git a/src/ORMExtension.php b/src/ORMExtension.php index bd2f635..bd4374d 100644 --- a/src/ORMExtension.php +++ b/src/ORMExtension.php @@ -20,10 +20,12 @@ public function loadConfiguration(): void { } final protected function registerORMService(string $tableName, array $fieldDefinitions): void { - if (isset($fieldDefinitions['serviceClassName'])) { + $serviceClassName = $fieldDefinitions['serviceClassName'] ?? ($fieldDefinitions['service'] ?? null); + $modelClassName = $fieldDefinitions['modelClassName'] ?? ($fieldDefinitions['model'] ?? null); + if ($serviceClassName) { $builder = $this->getContainerBuilder(); $factory = $builder->addDefinition($this->prefix($tableName . '.service')); - $factory->setFactory($fieldDefinitions['serviceClassName'], [$tableName, $fieldDefinitions['modelClassName']]); + $factory->setFactory($serviceClassName, [$tableName, $modelClassName]); } } } diff --git a/tests/ORM/ModelEvent.php b/tests/ORM/ModelEvent.php new file mode 100644 index 0000000..f532c8a --- /dev/null +++ b/tests/ORM/ModelEvent.php @@ -0,0 +1,9 @@ +event); + } +} diff --git a/tests/ORM/ServiceEvent.php b/tests/ORM/ServiceEvent.php new file mode 100644 index 0000000..8b3bc29 --- /dev/null +++ b/tests/ORM/ServiceEvent.php @@ -0,0 +1,9 @@ +load(function (Compiler $compiler) { + + $compiler->addExtension('orm', new ORMExtension()); + $compiler->addExtension('database', new DatabaseExtension()); + $compiler->loadConfig(__DIR__ . '/../config.neon'); + }); + + $this->container = new $class(); + } + + public function setUp() { + Environment::lock('DB', __TEMP__DIR__); + /** @var Explorer $explorer */ + $explorer = $this->container->getByType(Explorer::class); + $explorer->query("DELETE FROM `participant`; +DELETE FROM `event`; + +INSERT INTO `event` (event_id, begin, end) +VALUES (1, '2010-01-01', '2010-02-01'), + (2, '2010-02-01', '2010-03-01'), + (3, '2010-03-01', '2010-04-01'); +INSERT INTO `participant` (participant_id,event_id, name) +VALUES (1,1, 'Adam'), + (2,1, 'Bára'), + (3,1, 'Cecilia'), + (4,2, 'Dano'), + (5,2, 'Emil'), + (6,3, 'Fero'), + (7,3, 'Gustav'), + (8,3, 'Husák');"); + parent::setUp(); + } + +} diff --git a/tests/Tests/ClassLoadTest.phpt b/tests/Tests/ClassLoadTest.phpt new file mode 100644 index 0000000..ddad48d --- /dev/null +++ b/tests/Tests/ClassLoadTest.phpt @@ -0,0 +1,26 @@ +container->getByName('orm.event.service'); + Assert::type(AbstractService::class, $serviceEvent); + Assert::type(ServiceEvent::class, $serviceEvent); + + $serviceEvent = $this->container->getByName('orm.participant.service'); + Assert::type(AbstractService::class, $serviceEvent); + Assert::type(ServiceParticipant::class, $serviceEvent); + } +} + +$testCase = new ClassLoadTest(); +$testCase->run(); diff --git a/tests/Tests/ReferencedAccessTest.phpt b/tests/Tests/ReferencedAccessTest.phpt new file mode 100644 index 0000000..fd2883e --- /dev/null +++ b/tests/Tests/ReferencedAccessTest.phpt @@ -0,0 +1,45 @@ +container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->getTable()->fetch(); + $modelEvent = ReferencedAccessor::accessModel($participant, ModelEvent::class); + Assert::type(ModelEvent::class, $modelEvent); + } + + public function testSame(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->getTable()->fetch(); + $newModel = ReferencedAccessor::accessModel($participant, ModelParticipant::class); + Assert::same($participant, $newModel); + } + + public function testNoCandidate(): void { + /** @var ServiceEvent $service */ + $service = $this->container->getByType(ServiceEvent::class); + $event = $service->getTable()->fetch(); + Assert::exception(function () use ($event) { + ReferencedAccessor::accessModel($event, ModelParticipant::class); + }, CannotAccessModelException::class); + } + +} + +$testCase = new ReferencedAccessTest(); +$testCase->run(); diff --git a/tests/Tests/ServiceOperationTest.phpt b/tests/Tests/ServiceOperationTest.phpt new file mode 100644 index 0000000..ae396ab --- /dev/null +++ b/tests/Tests/ServiceOperationTest.phpt @@ -0,0 +1,122 @@ +container->getByType(ServiceParticipant::class); + $countBefore = $serviceParticipant->getTable()->count('*'); + + $newEvent = $serviceParticipant->createNewModel(['event_id' => 1, 'name' => 'Igor']); + $countAfter = $serviceParticipant->getTable()->count('*'); + + Assert::same($countBefore + 1, $countAfter); + Assert::type(ModelParticipant::class, $newEvent); + Assert::same('Igor', $newEvent->name); + } + + public function testCreateError(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $countBefore = $serviceParticipant->getTable()->count('*'); + Assert::exception(function () use ($serviceParticipant) { + $serviceParticipant->createNewModel(['event_id' => 4, 'name' => 'Igor']); + }, ModelException::class); + + $countAfter = $serviceParticipant->getTable()->count('*'); + + Assert::same($countBefore, $countAfter); + } + + public function testFindByPrimary(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->findByPrimary(1); + + Assert::same('Adam', $participant->name); + Assert::type(ModelParticipant::class, $participant); + + $nullParticipant = $serviceParticipant->findByPrimary(10); + Assert::null($nullParticipant); + } + + public function testUpdateSuccess(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->findByPrimary(2); + $serviceParticipant->updateModel2($participant, ['name' => 'Betka']); + $newParticipant = $serviceParticipant->refresh($participant); + Assert::same('Betka', $newParticipant->name); + Assert::type(ModelParticipant::class, $newParticipant); + } + + public function testUpdateError(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->findByPrimary(2); + + Assert::exception(function () use ($participant, $serviceParticipant) { + $serviceParticipant->updateModel2($participant, ['event_id' => 4]); + }, ModelException::class); + $newParticipant = $serviceParticipant->refresh($participant); + Assert::same('Bára', $newParticipant->name); + } + + public function testStoreExists(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->findByPrimary(2); + $newParticipant = $serviceParticipant->store($participant, ['name' => 'Betka']); + Assert::same('Betka', $newParticipant->name); + Assert::type(ModelParticipant::class, $newParticipant); + } + + public function testStoreNew(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $newParticipant = $serviceParticipant->store(null, ['event_id' => 1, 'name' => 'Igor']); + Assert::same('Igor', $newParticipant->name); + Assert::type(ModelParticipant::class, $newParticipant); + } + + public function testDelete(): void { + /** @var ServiceParticipant $serviceParticipant */ + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceParticipant->findByPrimary(2); + $countBefore = $serviceParticipant->getTable()->count('*'); + $serviceParticipant->dispose($participant); + $countAfter = $serviceParticipant->getTable()->count('*'); + Assert::same($countBefore - 1, $countAfter); + } + + public function testType(): void { + $serviceParticipant = $this->container->getByType(ServiceParticipant::class); + $serviceEvent = $this->container->getByType(ServiceEvent::class); + $event = $serviceEvent->getTable()->fetch(); + Assert::exception(function () use ($event, $serviceParticipant) { + $serviceParticipant->dispose($event); + }, \InvalidArgumentException::class); + } + + public function testDeleteError(): void { + $serviceEvent = $this->container->getByType(ServiceEvent::class); + $event = $serviceEvent->getTable()->fetch(); + Assert::exception(function () use ($event, $serviceEvent) { + $serviceEvent->dispose($event); + }, ModelException::class); + } + +} + +$testCase = new ServiceOperationTest(); +$testCase->run(); diff --git a/tests/Tests/TableSelectionTest.phpt b/tests/Tests/TableSelectionTest.phpt new file mode 100644 index 0000000..644f3ee --- /dev/null +++ b/tests/Tests/TableSelectionTest.phpt @@ -0,0 +1,60 @@ +container->getByType(ServiceEvent::class); + $selection = $serviceEvent->getTable(); + Assert::type(TypedTableSelection::class, $selection); + Assert::type(Selection::class, $selection); + $event = $selection->fetch(); + Assert::type(ActiveRow::class, $event); + Assert::type(ModelEvent::class, $event); + } + + public function testReferenced(): void { + /** @var ServiceParticipant $serviceEvent */ + $serviceEvent = $this->container->getByType(ServiceParticipant::class); + $participant = $serviceEvent->getTable()->fetch(); + + Assert::type(ModelParticipant::class, $participant); + $event = $participant->getEvent(); + Assert::type(ModelEvent::class, $event); + } + + public function testRelated(): void { + /** @var ServiceParticipant $serviceEvent */ + $serviceEvent = $this->container->getByType(ServiceEvent::class); + $event = $serviceEvent->getTable()->fetch(); + $row = $event->related('participant')->fetch(); + + Assert::false($row instanceof ModelParticipant); + $participant = ModelParticipant::createFromActiveRow($row); + Assert::type(ModelParticipant::class, $participant); + } + + public function testPassModel(): void { + /** @var ServiceParticipant $serviceEvent */ + $serviceEvent = $this->container->getByType(ServiceEvent::class); + $event = $serviceEvent->getTable()->fetch(); + $newEvent = ModelEvent::createFromActiveRow($event); + Assert::same($event, $newEvent); + } +} + +$testCase = new TableSelectionTest(); +$testCase->run(); diff --git a/tests/Tests/output/TableSelectionTest.actual b/tests/Tests/output/TableSelectionTest.actual new file mode 100644 index 0000000..690b2c8 --- /dev/null +++ b/tests/Tests/output/TableSelectionTest.actual @@ -0,0 +1,290 @@ +Fykosak\NetteORM\Tests\ORM\ModelEvent::__set_state(/* #07bd */ [ + 'table' => Fykosak\NetteORM\TypedTableSelection::__set_state(/* #f40c */ [ + 'modelClassName' => 'Fykosak\\NetteORM\\Tests\\ORM\\ModelEvent', + 'explorer' => Nette\Database\Explorer::__set_state(/* #ff7d */ [ + 'connection' => Nette\Database\Connection::__set_state(/* #497d */ [ + 'onConnect' => [], + 'onQuery' => [], + 'params' => ['mysql:host=127.0.0.1;dbname=nette_orm_test', 'root', 'fykos1'], + 'options' => [], + 'driver' => Nette\Database\Drivers\MySqlDriver::__set_state(/* #c223 */ [ + 'connection' => /* Nette\Database\Connection dumped on line 5 */, + 'version' => '5.7.33-0ubuntu0.18.04.1', + ]), + 'preprocessor' => Nette\Database\SqlPreprocessor::__set_state(/* #e855 */ [ + 'connection' => /* Nette\Database\Connection dumped on line 5 */, + 'driver' => /* Nette\Database\Drivers\MySqlDriver dumped on line 10 */, + 'params' => [ + 'SELECT * FROM `participant` WHERE (`participant`.`event_id` IN (?))', + [1, 2, 3], + ], + 'remaining' => [1, 2, 3], + 'counter' => 2, + 'useParams' => true, + 'arrayMode' => null, + ]), + 'pdo' => PDO::__set_state(/* #3880 */ []), + 'sql' => 'SELECT * FROM `event`', + ]), + 'structure' => Nette\Database\Structure::__set_state(/* #7243 */ [ + 'connection' => /* Nette\Database\Connection dumped on line 5 */, + 'cache' => Nette\Caching\Cache::__set_state(/* #6735 */ [ + 'storage' => Nette\Caching\Storages\FileStorage::__set_state(/* #fd3c */ [ + 'dir' => '../temp', + 'journal' => null, + 'locks' => null, + ]), + 'namespace' => "Nette.Database.Structure.4013f88097dca8446f3aa471806f6968\x00", + ]), + 'structure' => [ + 'tables' => [ + ['name' => 'event', 'view' => false], + ['name' => 'participant', 'view' => false], + ], + 'columns' => [ + 'event' => [ + [ + 'name' => 'event_id', + 'table' => 'event', + 'nativetype' => 'INT', + 'size' => 11, + 'nullable' => false, + 'default' => null, + 'autoincrement' => true, + 'primary' => true, + 'vendor' => [ + 'field' => 'event_id', + 'type' => 'int(11)', + 'collation' => null, + 'null' => 'NO', + 'key' => 'PRI', + 'default' => null, + 'extra' => 'auto_increment', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'begin', + 'table' => 'event', + 'nativetype' => 'DATETIME', + 'size' => null, + 'nullable' => false, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'begin', + 'type' => 'datetime', + 'collation' => null, + 'null' => 'NO', + 'key' => '', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'end', + 'table' => 'event', + 'nativetype' => 'DATETIME', + 'size' => null, + 'nullable' => false, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'end', + 'type' => 'datetime', + 'collation' => null, + 'null' => 'NO', + 'key' => '', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + ], + 'participant' => [ + [ + 'name' => 'participant_id', + 'table' => 'participant', + 'nativetype' => 'INT', + 'size' => 11, + 'nullable' => false, + 'default' => null, + 'autoincrement' => true, + 'primary' => true, + 'vendor' => [ + 'field' => 'participant_id', + 'type' => 'int(11)', + 'collation' => null, + 'null' => 'NO', + 'key' => 'PRI', + 'default' => null, + 'extra' => 'auto_increment', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'event_id', + 'table' => 'participant', + 'nativetype' => 'INT', + 'size' => 11, + 'nullable' => false, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'event_id', + 'type' => 'int(11)', + 'collation' => null, + 'null' => 'NO', + 'key' => 'MUL', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'name', + 'table' => 'participant', + 'nativetype' => 'VARCHAR', + 'size' => 64, + 'nullable' => true, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'name', + 'type' => 'varchar(64)', + 'collation' => 'latin1_swedish_ci', + 'null' => 'YES', + 'key' => '', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + ], + ], + 'primary' => ['event' => 'event_id', 'participant' => 'participant_id'], + 'belongsTo' => ['participant' => ['event_id' => 'event']], + 'hasMany' => ['event' => ['participant' => ['event_id']]], + ], + 'isRebuilt' => false, + ]), + 'conventions' => Nette\Database\Conventions\DiscoveredConventions::__set_state(/* #45ff */ [ + 'structure' => /* Nette\Database\Structure dumped on line 29 */, + ]), + 'cacheStorage' => /* Nette\Caching\Storages\FileStorage dumped on line 32 */, + ]), + 'context' => /* Nette\Database\Explorer dumped on line 4 */, + 'conventions' => /* Nette\Database\Conventions\DiscoveredConventions dumped on line 182 */, + 'cache' => null, + 'sqlBuilder' => Nette\Database\Table\SqlBuilder::__set_state(/* #1d52 */ [ + 'tableName' => 'event', + 'conventions' => /* Nette\Database\Conventions\DiscoveredConventions dumped on line 182 */, + 'delimitedTable' => '`event`', + 'select' => [], + 'where' => [], + 'joinCondition' => [], + 'conditions' => [], + 'parameters' => [ + 'select' => [], + 'joinCondition' => [], + 'where' => [], + 'group' => [], + 'having' => [], + 'order' => [], + 'joinConditionSorted' => [], + ], + 'order' => [], + 'limit' => null, + 'offset' => null, + 'group' => '', + 'having' => '', + 'reservedTableNames' => ['event' => 'event'], + 'aliases' => [], + 'currentAlias' => null, + 'driver' => /* Nette\Database\Drivers\MySqlDriver dumped on line 10 */, + 'structure' => /* Nette\Database\Structure dumped on line 29 */, + 'cacheTableList' => null, + 'expandingJoins' => [], + ]), + 'name' => 'event', + 'primary' => 'event_id', + 'primarySequence' => false, + 'rows' => [ + 1 => /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 1 */, + Fykosak\NetteORM\Tests\ORM\ModelEvent::__set_state(/* #c55d */ [ + 'table' => /* Fykosak\NetteORM\TypedTableSelection dumped on line 2 */, + 'data' => [ + 'event_id' => 2, + 'begin' => Nette\Utils\DateTime::__set_state(/* #6032 */ [ + 'date' => '2010-02-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + 'end' => Nette\Utils\DateTime::__set_state(/* #024f */ [ + 'date' => '2010-03-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + ], + 'dataRefreshed' => false, + ]), + Fykosak\NetteORM\Tests\ORM\ModelEvent::__set_state(/* #4351 */ [ + 'table' => /* Fykosak\NetteORM\TypedTableSelection dumped on line 2 */, + 'data' => [ + 'event_id' => 3, + 'begin' => Nette\Utils\DateTime::__set_state(/* #635c */ [ + 'date' => '2010-03-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + 'end' => Nette\Utils\DateTime::__set_state(/* #a4bc */ [ + 'date' => '2010-04-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + ], + 'dataRefreshed' => false, + ]), + ], + 'data' => [ + 1 => /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 1 */, + /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 225 */, + /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 242 */, + ], + 'dataRefreshed' => false, + 'globalRefCache' => ['' => null], + 'refCache' => null, + 'generalCacheKey' => null, + 'specificCacheKey' => null, + 'aggregation' => [], + 'accessedColumns' => ['event_id' => true], + 'previousAccessedColumns' => null, + 'observeCache' => /* Fykosak\NetteORM\TypedTableSelection dumped on line 2 */, + 'keys' => [], + ]), + 'data' => [ + 'event_id' => 1, + 'begin' => Nette\Utils\DateTime::__set_state(/* #9b19 */ [ + 'date' => '2010-01-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + 'end' => Nette\Utils\DateTime::__set_state(/* #d610 */ [ + 'date' => '2010-02-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + ], + 'dataRefreshed' => false, +]) diff --git a/tests/Tests/output/TableSelectionTest.expected b/tests/Tests/output/TableSelectionTest.expected new file mode 100644 index 0000000..202d62c --- /dev/null +++ b/tests/Tests/output/TableSelectionTest.expected @@ -0,0 +1,290 @@ +Fykosak\NetteORM\Tests\ORM\ModelEvent::__set_state(/* #f2b2 */ [ + 'table' => Fykosak\NetteORM\TypedTableSelection::__set_state(/* #25b4 */ [ + 'modelClassName' => 'Fykosak\\NetteORM\\Tests\\ORM\\ModelEvent', + 'explorer' => Nette\Database\Explorer::__set_state(/* #ff7d */ [ + 'connection' => Nette\Database\Connection::__set_state(/* #497d */ [ + 'onConnect' => [], + 'onQuery' => [], + 'params' => ['mysql:host=127.0.0.1;dbname=nette_orm_test', 'root', 'fykos1'], + 'options' => [], + 'driver' => Nette\Database\Drivers\MySqlDriver::__set_state(/* #c223 */ [ + 'connection' => /* Nette\Database\Connection dumped on line 5 */, + 'version' => '5.7.33-0ubuntu0.18.04.1', + ]), + 'preprocessor' => Nette\Database\SqlPreprocessor::__set_state(/* #e855 */ [ + 'connection' => /* Nette\Database\Connection dumped on line 5 */, + 'driver' => /* Nette\Database\Drivers\MySqlDriver dumped on line 10 */, + 'params' => [ + 'SELECT * FROM `participant` WHERE (`participant`.`event_id` IN (?))', + [1, 2, 3], + ], + 'remaining' => [1, 2, 3], + 'counter' => 2, + 'useParams' => true, + 'arrayMode' => null, + ]), + 'pdo' => PDO::__set_state(/* #3880 */ []), + 'sql' => 'SELECT * FROM `event`', + ]), + 'structure' => Nette\Database\Structure::__set_state(/* #7243 */ [ + 'connection' => /* Nette\Database\Connection dumped on line 5 */, + 'cache' => Nette\Caching\Cache::__set_state(/* #6735 */ [ + 'storage' => Nette\Caching\Storages\FileStorage::__set_state(/* #fd3c */ [ + 'dir' => '../temp', + 'journal' => null, + 'locks' => null, + ]), + 'namespace' => "Nette.Database.Structure.4013f88097dca8446f3aa471806f6968\x00", + ]), + 'structure' => [ + 'tables' => [ + ['name' => 'event', 'view' => false], + ['name' => 'participant', 'view' => false], + ], + 'columns' => [ + 'event' => [ + [ + 'name' => 'event_id', + 'table' => 'event', + 'nativetype' => 'INT', + 'size' => 11, + 'nullable' => false, + 'default' => null, + 'autoincrement' => true, + 'primary' => true, + 'vendor' => [ + 'field' => 'event_id', + 'type' => 'int(11)', + 'collation' => null, + 'null' => 'NO', + 'key' => 'PRI', + 'default' => null, + 'extra' => 'auto_increment', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'begin', + 'table' => 'event', + 'nativetype' => 'DATETIME', + 'size' => null, + 'nullable' => false, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'begin', + 'type' => 'datetime', + 'collation' => null, + 'null' => 'NO', + 'key' => '', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'end', + 'table' => 'event', + 'nativetype' => 'DATETIME', + 'size' => null, + 'nullable' => false, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'end', + 'type' => 'datetime', + 'collation' => null, + 'null' => 'NO', + 'key' => '', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + ], + 'participant' => [ + [ + 'name' => 'participant_id', + 'table' => 'participant', + 'nativetype' => 'INT', + 'size' => 11, + 'nullable' => false, + 'default' => null, + 'autoincrement' => true, + 'primary' => true, + 'vendor' => [ + 'field' => 'participant_id', + 'type' => 'int(11)', + 'collation' => null, + 'null' => 'NO', + 'key' => 'PRI', + 'default' => null, + 'extra' => 'auto_increment', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'event_id', + 'table' => 'participant', + 'nativetype' => 'INT', + 'size' => 11, + 'nullable' => false, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'event_id', + 'type' => 'int(11)', + 'collation' => null, + 'null' => 'NO', + 'key' => 'MUL', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + [ + 'name' => 'name', + 'table' => 'participant', + 'nativetype' => 'VARCHAR', + 'size' => 64, + 'nullable' => true, + 'default' => null, + 'autoincrement' => false, + 'primary' => false, + 'vendor' => [ + 'field' => 'name', + 'type' => 'varchar(64)', + 'collation' => 'latin1_swedish_ci', + 'null' => 'YES', + 'key' => '', + 'default' => null, + 'extra' => '', + 'privileges' => 'select,insert,update,references', + 'comment' => '', + ], + ], + ], + ], + 'primary' => ['event' => 'event_id', 'participant' => 'participant_id'], + 'belongsTo' => ['participant' => ['event_id' => 'event']], + 'hasMany' => ['event' => ['participant' => ['event_id']]], + ], + 'isRebuilt' => false, + ]), + 'conventions' => Nette\Database\Conventions\DiscoveredConventions::__set_state(/* #45ff */ [ + 'structure' => /* Nette\Database\Structure dumped on line 29 */, + ]), + 'cacheStorage' => /* Nette\Caching\Storages\FileStorage dumped on line 32 */, + ]), + 'context' => /* Nette\Database\Explorer dumped on line 4 */, + 'conventions' => /* Nette\Database\Conventions\DiscoveredConventions dumped on line 182 */, + 'cache' => null, + 'sqlBuilder' => Nette\Database\Table\SqlBuilder::__set_state(/* #1326 */ [ + 'tableName' => 'event', + 'conventions' => /* Nette\Database\Conventions\DiscoveredConventions dumped on line 182 */, + 'delimitedTable' => '`event`', + 'select' => [], + 'where' => [], + 'joinCondition' => [], + 'conditions' => [], + 'parameters' => [ + 'select' => [], + 'joinCondition' => [], + 'where' => [], + 'group' => [], + 'having' => [], + 'order' => [], + 'joinConditionSorted' => [], + ], + 'order' => [], + 'limit' => null, + 'offset' => null, + 'group' => '', + 'having' => '', + 'reservedTableNames' => ['event' => 'event'], + 'aliases' => [], + 'currentAlias' => null, + 'driver' => /* Nette\Database\Drivers\MySqlDriver dumped on line 10 */, + 'structure' => /* Nette\Database\Structure dumped on line 29 */, + 'cacheTableList' => null, + 'expandingJoins' => [], + ]), + 'name' => 'event', + 'primary' => 'event_id', + 'primarySequence' => false, + 'rows' => [ + 1 => /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 1 */, + Fykosak\NetteORM\Tests\ORM\ModelEvent::__set_state(/* #431e */ [ + 'table' => /* Fykosak\NetteORM\TypedTableSelection dumped on line 2 */, + 'data' => [ + 'event_id' => 2, + 'begin' => Nette\Utils\DateTime::__set_state(/* #ab17 */ [ + 'date' => '2010-02-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + 'end' => Nette\Utils\DateTime::__set_state(/* #fccd */ [ + 'date' => '2010-03-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + ], + 'dataRefreshed' => false, + ]), + Fykosak\NetteORM\Tests\ORM\ModelEvent::__set_state(/* #672e */ [ + 'table' => /* Fykosak\NetteORM\TypedTableSelection dumped on line 2 */, + 'data' => [ + 'event_id' => 3, + 'begin' => Nette\Utils\DateTime::__set_state(/* #65ec */ [ + 'date' => '2010-03-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + 'end' => Nette\Utils\DateTime::__set_state(/* #9234 */ [ + 'date' => '2010-04-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + ], + 'dataRefreshed' => false, + ]), + ], + 'data' => [ + 1 => /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 1 */, + /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 225 */, + /* Fykosak\NetteORM\Tests\ORM\ModelEvent dumped on line 242 */, + ], + 'dataRefreshed' => false, + 'globalRefCache' => ['' => null], + 'refCache' => null, + 'generalCacheKey' => null, + 'specificCacheKey' => null, + 'aggregation' => [], + 'accessedColumns' => ['event_id' => true], + 'previousAccessedColumns' => null, + 'observeCache' => /* Fykosak\NetteORM\TypedTableSelection dumped on line 2 */, + 'keys' => [], + ]), + 'data' => [ + 'event_id' => 1, + 'begin' => Nette\Utils\DateTime::__set_state(/* #f848 */ [ + 'date' => '2010-01-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + 'end' => Nette\Utils\DateTime::__set_state(/* #c5b9 */ [ + 'date' => '2010-02-01 00:00:00.000000', + 'timezone_type' => 3, + 'timezone' => 'Europe/Prague', + ]), + ], + 'dataRefreshed' => false, +]) diff --git a/tests/config.local.neon.example b/tests/config.local.neon.example new file mode 100644 index 0000000..00f816c --- /dev/null +++ b/tests/config.local.neon.example @@ -0,0 +1,4 @@ +database: + dsn: 'mysql:host=127.0.0.1;dbname=nette_orm_test' + user: + password: diff --git a/tests/config.neon b/tests/config.neon new file mode 100644 index 0000000..bc9c80e --- /dev/null +++ b/tests/config.neon @@ -0,0 +1,12 @@ +services: + - Nette\Caching\Storages\FileStorage('../temp') +orm: + event: + modelClassName: Fykosak\NetteORM\Tests\ORM\ModelEvent + serviceClassName: Fykosak\NetteORM\Tests\ORM\ServiceEvent + participant: + model: Fykosak\NetteORM\Tests\ORM\ModelParticipant + service: Fykosak\NetteORM\Tests\ORM\ServiceParticipant + +includes: + - config.local.neon diff --git a/tests/php.ini b/tests/php.ini new file mode 100644 index 0000000..480fc7a --- /dev/null +++ b/tests/php.ini @@ -0,0 +1,26 @@ +extension=fileinfo.so +extension=curl.so +extension=dom.so +extension=gettext.so +extension=iconv.so +extension=fileinfo.so +extension=json.so +extension=mbstring.so +extension=mysqlnd.so +extension=pdo.so +extension=pdo_mysql.so +extension=simplexml.so +extension=soap.so +extension=tokenizer.so +extension=xml.so +extension=xsl.so +extension=fileinfo.so +zend_extension=xdebug.so +xdebug.mode='coverage' + +; see http://stackoverflow.com/questions/2904862/issues-with-php-5-3-and-sessions-folder +session.gc_probability=0 + +date.timezone="Europe/Prague" +display_startup_errors = Off + diff --git a/tests/resource/schema.sql b/tests/resource/schema.sql new file mode 100644 index 0000000..d617e81 --- /dev/null +++ b/tests/resource/schema.sql @@ -0,0 +1,21 @@ +CREATE DATABASE IF NOT EXISTS `nette_orm_test`; + +USE `nette_orm_test`; +CREATE TABLE IF NOT EXISTS `event` +( + `event_id` INT PRIMARY KEY AUTO_INCREMENT NOT NULL, + `begin` DATETIME NOT NULL, + `end` DATETIME NOT NULL +) ENGINE = InnoDB; + +CREATE TABLE IF NOT EXISTS `participant` +( + `participant_id` INT PRIMARY KEY AUTO_INCREMENT NOT NULL, + `event_id` INT NOT NULL, + `name` VARCHAR(64), + CONSTRAINT `fk_participant_event` + FOREIGN KEY (`event_id`) + REFERENCES `event` (`event_id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION +) ENGINE = InnoDB; From 7c2c3063a64e89b6e2c349b4ebf99540dc504256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:17:50 +0100 Subject: [PATCH 02/23] Create php.yml --- .github/workflows/php.yml | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..e844818 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,45 @@ +name: PHP (Nette Tester) + +on: [push, pull_request] + +jobs: + test: + name: PHP ${{ matrix.php }} with ${{ matrix.database }} + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + php: [ '7.4' ] + database: [ 'mysql' ] + steps: + # MariaDB container has to be started in advance to initialize itself before using it. + - uses: actions/checkout@v2 + name: Checkout + with: + submodules: recursive + - uses: shivammathur/setup-php@v2 + name: Setup PHP + with: + php-version: ${{ matrix.php }} + extensions: curl, mbstring, mysql, soap, xml + tools: composer + ini-values: session.gc_probability=0, date.timezone="Europe/Prague", display_startup_errors = Off + - name: Composer install + run: composer install --no-progress --prefer-dist + - name: DB configuration + run: | + "sed -e 's/user:/user: runner/' tests/config.local.neon.sample > tests/config.local.neon" + - name: Start and prepare MySQL + run: | + sudo service mysql start + sudo mysql -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY ''; CREATE USER 'runner'@'localhost' IDENTIFIED BY ''; GRANT ALL PRIVILEGES ON * . * TO 'runner'@'localhost';" + - run: composer run-script initTestDatabase + name: Init test database + - run: composer run-script test + name: Test + - if: failure() + name: Failure output + uses: actions/upload-artifact@v2 + with: + name: output + path: tests/**/*.actual From 1d5c8c8893c8f93af887be6aaab657202db9b843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:18:36 +0100 Subject: [PATCH 03/23] Add scripts --- composer.json | 3 +++ tests/config.local.neon.example | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1578df6..03a92c8 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,9 @@ } }, "scripts": { + "initTestDatabse": [ + "mysql nette_orm_test < tests/resource/schema.sql " + ], "clearCache": [ "rm -r tests/temp/*" ], diff --git a/tests/config.local.neon.example b/tests/config.local.neon.example index 00f816c..2c4e467 100644 --- a/tests/config.local.neon.example +++ b/tests/config.local.neon.example @@ -1,4 +1,4 @@ database: dsn: 'mysql:host=127.0.0.1;dbname=nette_orm_test' - user: - password: + user: + password: From b917eba2f3301d67a8e980e9b26cd80964927f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:20:14 +0100 Subject: [PATCH 04/23] Update php.yml --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index e844818..ee4887e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,7 +28,7 @@ jobs: run: composer install --no-progress --prefer-dist - name: DB configuration run: | - "sed -e 's/user:/user: runner/' tests/config.local.neon.sample > tests/config.local.neon" + "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | sudo service mysql start From 74d8296a14510dd906e9fc9e583af880c41e6bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:25:24 +0100 Subject: [PATCH 05/23] Update php.yml --- .github/workflows/php.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ee4887e..d1d67ff 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,6 +28,7 @@ jobs: run: composer install --no-progress --prefer-dist - name: DB configuration run: | + "pwd" "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | From 3359f7ce9643611afa34c69d694a6fb1ceb1a7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:28:18 +0100 Subject: [PATCH 06/23] Update php.yml --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index d1d67ff..f746294 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,7 +28,7 @@ jobs: run: composer install --no-progress --prefer-dist - name: DB configuration run: | - "pwd" + "ls tests/" "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | From ccf8308f8db726653e740f2695f28bb3597948d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:29:41 +0100 Subject: [PATCH 07/23] Update php.yml --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f746294..c8e0f51 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,7 +28,7 @@ jobs: run: composer install --no-progress --prefer-dist - name: DB configuration run: | - "ls tests/" + "ls" "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | From caca77f8c9c1261e9096cf1db90fbe595464fb91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:31:20 +0100 Subject: [PATCH 08/23] Update php.yml --- .github/workflows/php.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c8e0f51..672b970 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -29,6 +29,8 @@ jobs: - name: DB configuration run: | "ls" + "ls tests/" + "ls tests" "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | From ea5b9de2610b2a4963c0e18d1710802038806432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:32:22 +0100 Subject: [PATCH 09/23] Update php.yml --- .github/workflows/php.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 672b970..82c7e90 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,8 +28,7 @@ jobs: run: composer install --no-progress --prefer-dist - name: DB configuration run: | - "ls" - "ls tests/" + "ls -lA" "ls tests" "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL From 8f968bbac6109bfc213db48ed433a4cdbead0a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:33:52 +0100 Subject: [PATCH 10/23] Update php.yml --- .github/workflows/php.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 82c7e90..c8bcff7 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,8 +28,8 @@ jobs: run: composer install --no-progress --prefer-dist - name: DB configuration run: | - "ls -lA" - "ls tests" + ls -l + ls tests "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | From d9cd397932bcc001ad166ce99fcd0860e351934e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:35:33 +0100 Subject: [PATCH 11/23] Update php.yml --- .github/workflows/php.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c8bcff7..80407d4 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -27,10 +27,7 @@ jobs: - name: Composer install run: composer install --no-progress --prefer-dist - name: DB configuration - run: | - ls -l - ls tests - "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" + run: "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" - name: Start and prepare MySQL run: | sudo service mysql start From b88cf53a400b12ca2c3f0cce5851c9d06ae0dda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:36:43 +0100 Subject: [PATCH 12/23] fix script name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 03a92c8..2e63de4 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ } }, "scripts": { - "initTestDatabse": [ + "initTestDatabase": [ "mysql nette_orm_test < tests/resource/schema.sql " ], "clearCache": [ From 2beee6e9201821806344c1b2184aa11f40665326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:38:27 +0100 Subject: [PATCH 13/23] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2e63de4..6f90fb8 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ }, "scripts": { "initTestDatabase": [ - "mysql nette_orm_test < tests/resource/schema.sql " + "mysql < tests/resource/schema.sql " ], "clearCache": [ "rm -r tests/temp/*" From c0526f2c9fb58d88ccd4ba0e27027b338ae50c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:41:08 +0100 Subject: [PATCH 14/23] fix temp dir --- tests/temp/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/temp/.gitignore diff --git a/tests/temp/.gitignore b/tests/temp/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/tests/temp/.gitignore @@ -0,0 +1 @@ +* From d93424aec7b02c19196d0b527e9421811034c36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:46:19 +0100 Subject: [PATCH 15/23] Add gitignore --- .gitignore | 3 ++- tests/temp/.gitignore | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 83d3e5f..32ce49d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ /tests/config.local.neon -/tests/temp/ +/tests/temp/* +!/tests/temp/.gitignore diff --git a/tests/temp/.gitignore b/tests/temp/.gitignore index 72e8ffc..b498fd4 100644 --- a/tests/temp/.gitignore +++ b/tests/temp/.gitignore @@ -1 +1 @@ -* +/ From b209f41eac7c1365002d7e903404c2b3ae844571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:48:03 +0100 Subject: [PATCH 16/23] fix cache clearing --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 6f90fb8..d6596a8 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,6 @@ "rm -r tests/temp/*" ], "test": [ - "@clearCache", "vendor/bin/tester tests -p php -s -c tests/php.ini -j 1" ], "testCoverage": [ From abb35a3422df205d23acf314e5407ceb73c12478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:54:58 +0100 Subject: [PATCH 17/23] Update php.yml --- .github/workflows/php.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 80407d4..c35cfef 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -34,8 +34,11 @@ jobs: sudo mysql -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY ''; CREATE USER 'runner'@'localhost' IDENTIFIED BY ''; GRANT ALL PRIVILEGES ON * . * TO 'runner'@'localhost';" - run: composer run-script initTestDatabase name: Init test database - - run: composer run-script test + - run: composer run-script testCoverage name: Test + - uses: actions/download-artifact@v2 + with: + name: coverage.html - if: failure() name: Failure output uses: actions/upload-artifact@v2 From da5a059c6341f63a739ae998b4206f91d5e111bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:55:27 +0100 Subject: [PATCH 18/23] Update composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index d6596a8..bdfe35d 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,6 @@ "vendor/bin/tester tests -p php -s -c tests/php.ini -j 1" ], "testCoverage": [ - "@clearCache", "vendor/bin/tester tests -p php --coverage coverage.html --coverage-src src/ -s -c tests/php.ini -j 1" ] } From 1447cac025539b0339ae7a3d97e667a66e5851cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 03:59:55 +0100 Subject: [PATCH 19/23] Update php.yml --- .github/workflows/php.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c35cfef..4c0477e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -38,7 +38,8 @@ jobs: name: Test - uses: actions/download-artifact@v2 with: - name: coverage.html + name: ./coverage.html + - if: failure() name: Failure output uses: actions/upload-artifact@v2 From af02dd78b0cc975e1283cf265d575bdd7e24413f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 04:03:41 +0100 Subject: [PATCH 20/23] Update php.yml --- .github/workflows/php.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4c0477e..3209d4b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -35,11 +35,7 @@ jobs: - run: composer run-script initTestDatabase name: Init test database - run: composer run-script testCoverage - name: Test - - uses: actions/download-artifact@v2 - with: - name: ./coverage.html - + name: Test - if: failure() name: Failure output uses: actions/upload-artifact@v2 From b35e18967af6325ef016ef7babd39d1fb649f105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 04:03:51 +0100 Subject: [PATCH 21/23] Create php.yml From fcd4df3180b6ed9de66ed370bc7e2b94176de133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 04:06:19 +0100 Subject: [PATCH 22/23] Update php.yml --- .github/workflows/php.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 3209d4b..24b900a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -35,7 +35,12 @@ jobs: - run: composer run-script initTestDatabase name: Init test database - run: composer run-script testCoverage - name: Test + name: Test + - name: Archive code coverage results + uses: actions/upload-artifact@v2 + with: + name: code-coverage-report + path: coverage.html - if: failure() name: Failure output uses: actions/upload-artifact@v2 From fe551c58d37a0c3a4af58beeca4a83df3ddeb269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mi=C5=A1o=20=C4=8Cerve=C5=88=C3=A1k?= Date: Thu, 25 Mar 2021 04:16:14 +0100 Subject: [PATCH 23/23] Update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7577f75..fdf3a40 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Nette ORM +![GitHub branch checks state](https://img.shields.io/github/checks-status/fykosak/nette-orm/master) + + ## install ### Create ORM model