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:----D+Mh7YYtxqYrJ1dwxgstYzZFq8jdDNwIcrA5mf4yFLnTej5MYgOdwLh1lUyLHE3GZjKMwimNViAKw2hV6BvNEGy+osaMIhdM9WRcNSo1CAj56RAdAqt7vkbwNBHBh4svsSiZGgYDsCoZTh6dbwg9JetAXzRJ6Z86GFzOJNlKD0JQL02UT9xZ/nZd9SxaxLAJCvEieHLcdFw3xB7LqyPwDXim52JnFvOfLtT/l6m1sscLXyZtJn6kmV8rV0ryH2+INnwh1aFTT02OsJMdOAa1uHYaBMU00/ZhXe4Gy1fLvfVnO8UB46pc7MmUC55ukxarVBLaRt6Ak8bjXalorF/j1q5ldJdWQ/W8ZQnDM6rxkMRqc+3jP/wrFvN7eMe6AEREeb/xhbhQ/Y6Sa4yN9YKWNW6IpYu6iCI842sxw6ZD2imjXAJaK3FSSsnYdC7PtvUkMOaDMrcBNM4iCX1pLanxHFlsiBAGMbmG86pnsHX+u8NIe5RQESUxHntd+fssuvW7qG3LcD6SgDh+PUDJC1QbDtv3m/7N7nq9DQ771uTimohd+lHrz3s4S6AbxhRoOMS4PQYflcM2YItcR85sDskn3rStMT+DhuhW+2H6yDSRX1ATpsMFwmVAn524GE5hdKHbxrptijBhahWpovTzjKTZ7qhXdqgzCDuNA3Vn/bQ32vc=----ATTACHMENT:----OTA1MzM0MzA3NDk3MjcxNiAyNTQ4MzEwMjkxNDY2MDcgNDExNjAyOTMxMDkwMzg3OQ==