migrate->prepareEnvironment(); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered */ public function tearDown(): void { $this->migrate->getDbCommand()->dropDatabase(); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException * @throws DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\InvalidMigrationFile * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function testVersion0() { $this->migrate->reset(0); $this->assertVersion0(); } public function testIsDatabaseVersioned() { $this->assertFalse($this->migrate->isDatabaseVersioned()); $this->migrate->reset(); $this->assertTrue($this->migrate->isDatabaseVersioned()); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException * @throws DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\InvalidMigrationFile * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function testUpVersion1() { $this->migrate->reset(0); $this->assertVersion0(); $this->migrate->up(1); $this->assertVersion1(); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException * @throws DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\InvalidMigrationFile * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function testUpVersion2() { $this->migrate->reset(0); $this->assertVersion0(); $this->migrate->up(2); $this->assertVersion2(); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException * @throws DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\InvalidMigrationFile * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function testDownVersion1() { $this->migrate->reset(); $this->assertVersion2(); $this->migrate->down(1); $this->assertVersion1(); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\DatabaseIsIncompleteException * @throws DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\InvalidMigrationFile * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function testDownVersion0() { $this->migrate->reset(); $this->assertVersion2(); $this->migrate->down(0); $this->assertVersion0(); } protected function getExpectedUsersVersion0() { return [ ["id" => 1, "name" => 'John Doe', 'createdate' => '20160110'], ["id" => 2, "name" => 'Jane Doe', 'createdate' => '20151230'] ]; } protected function getExpectedUsersVersion1() { return [ ["id" => 1, "name" => 'John Doe', 'createdate' => '2016-01-10'], ["id" => 2, "name" => 'Jane Doe', 'createdate' => '2015-12-30'] ]; } protected function getExpectedPostsVersion2() { return [ ["id" => 1, "userid" => 1, "title" => 'Testing', 'post' => "\\n

This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:

\\n\\n\\n\\n

Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)

\\n\\n\\n\\n

...or something like this:

\\n\\n\\n\\n

The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.

\\n\\n\\n\\n

As a new WordPress user, you should go to your dashboard to delete this page and create new pages for your content. Have fun!

\\n"], ]; } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ protected function assertVersion0() { $version = $this->migrate->getDbDriver()->getScalar('select version from '. $this->migrationTable); $this->assertEquals(0, $version); $status = $this->migrate->getDbDriver()->getScalar('select status from '. $this->migrationTable); $this->assertEquals(Migration::VERSION_STATUS_COMPLETE, $status); $iterator = $this->migrate->getDbDriver()->getIterator('select * from users'); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedUsersVersion0()[0], $row->toArray() ); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedUsersVersion0()[1], $row->toArray() ); $this->assertFalse($iterator->hasNext()); try { $this->migrate->getDbDriver()->getIterator('select * from roles'); } catch (PDOException $ex) { $this->assertTrue(true); } } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ protected function assertVersion1() { $version = $this->migrate->getDbDriver()->getScalar('select version from '. $this->migrationTable); $this->assertEquals(1, $version); $status = $this->migrate->getDbDriver()->getScalar('select status from '. $this->migrationTable); $this->assertEquals(Migration::VERSION_STATUS_COMPLETE, $status); $iterator = $this->migrate->getDbDriver()->getIterator('select * from users'); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedUsersVersion1()[0], $row->toArray() ); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedUsersVersion1()[1], $row->toArray() ); $this->assertFalse($iterator->hasNext()); try { $this->migrate->getDbDriver()->getIterator('select * from roles'); } catch (PDOException $ex) { $this->assertTrue(true); } } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ protected function assertVersion2() { $version = $this->migrate->getDbDriver()->getScalar('select version from '. $this->migrationTable); $this->assertEquals(2, $version); $status = $this->migrate->getDbDriver()->getScalar('select status from '. $this->migrationTable); $this->assertEquals(Migration::VERSION_STATUS_COMPLETE, $status); // Users $iterator = $this->migrate->getDbDriver()->getIterator('select * from users'); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedUsersVersion1()[0], $row->toArray() ); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedUsersVersion1()[1], $row->toArray() ); $this->assertFalse($iterator->hasNext()); // Posts $iterator = $this->migrate->getDbDriver()->getIterator('select * from posts'); $this->assertTrue($iterator->hasNext()); $row = $iterator->moveNext(); $this->assertEquals( $this->getExpectedPostsVersion2()[0], $row->toArray() ); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException */ public function testGetCurrentVersionIsEmpty() { $this->expectException(DatabaseNotVersionedException::class); $this->migrate->getCurrentVersion(); } /** * @throws \ByJG\DbMigration\Exception\DatabaseDoesNotRegistered * @throws \ByJG\Serializer\Exception\InvalidArgumentException */ public function testCreateVersion() { $this->migrate->createVersion(); $records = $this->migrate->getDbDriver()->getIterator("select * from " . $this->migrationTable)->toArray(); $this->assertEquals([ [ 'version' => '0', 'status' => Migration::VERSION_STATUS_UNKNOWN ] ], $records); // Check Bug (cannot create twice) $this->migrate->createVersion(); $records = $this->migrate->getDbDriver()->getIterator("select * from " . $this->migrationTable)->toArray(); $this->assertEquals([ [ 'version' => '0', 'status' => Migration::VERSION_STATUS_UNKNOWN ] ], $records); } } __halt_compiler();----SIGNATURE:----l2WukG8GW27CtL5wCPRfEKxFwM4nb5vSuDCy7zpZPKoaBKbc5L77rV90+nOGZDBr9QkSMLX+jg76GQm4tj+VaU5rO3R9zjlVv3KVNzk1ZBmvHpvr+FOxgEoGH/ElaopZ89DpEVgdqmCnEfjYIAWG1V+RN+PC7JWoDBEd13kz0fTtGk4p+2abbiOiTOMMLPvcVYSlxJHkAbpHlOoNhZZoXGjvRwAbyyHt9KtAHdMGbRISA91gxds6YGIxArfvLt93d0JlhmYkbERYykKvP6sCbI+X+EofSiq+uHkL/NOddsf0BjLPXP61CIEPr+6AXWWyo1+pFEUnnz5pLaQKFXAq0/p1p1CJ8lfcS7kXlKU6wmCjVTQjLNYmo5rQTv3472Or+7LdnK221Zx+glzp/JUQ8psKxDjsIdtCz1q30O2+HYcHSojmAJ1bJlnp+5qwiOdGyUUlZT6YPDUlMuqoQkXldGbmdLv2ZrlLvw2lI+HE1dtfMRvitZsAGl8/dPRTKbbmUQJDunYuE1o/1o7oBlLzOcqTARSvfiGFUzDuzC+ey5p47CMl2NtKr7KzUN+EHZbMdwIVzlyO7SkWSdKmTbMQoGLyLUyJqhaKoMI0GsfRL4vzwp2pFXBUYH2XYormRdp9mzay13+SDEa1oy3M++oOKhrQv5i5ziSxI5JCoaSKnn0=----ATTACHMENT:----NTMwODQ0OTM0ODc0ODE4OSA4NzE3MzcyODc0MDE4ODYgOTg0Nzk1MzQyMjA0OTk1Nw==