object = new Route(); $this->obj1 = Factory::getDbRelationalInstance('sqlite:///tmp/a.db'); $this->obj2 = Factory::getDbRelationalInstance('sqlite:///tmp/b.db'); $this->obj3 = Factory::getDbRelationalInstance('sqlite:///tmp/c.db'); $this->object->addDbDriverInterface('route1', 'sqlite:///tmp/a.db'); $this->object->addDbDriverInterface('route2', $this->obj2); $this->object->addDbDriverInterface('route3', 'sqlite:///tmp/c.db'); } public function tearDown(): void { $this->object = null; $this->obj1 = null; $this->obj2 = null; $this->obj3 = null; } public function testAddRouteForSelect() { $this->object->addRouteForSelect('route3', 'mytable'); $this->object->addRouteForSelect('route2'); $this->assertEquals($this->obj2, $this->object->matchRoute('SELECT field1, fields fRom table')); $this->assertEquals($this->obj3, $this->object->matchRoute('SELECT field1, fields fRom mytable')); } /** * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function testAddRouteForSelectFail() { $this->expectException(\ByJG\AnyDataset\Db\Exception\RouteNotMatchedException::class); $this->object->addRouteForSelect('route3', 'mytable'); $this->object->addRouteForSelect('route2'); $this->object->matchRoute('update mytable set a=1'); } public function testAddRouteForInsert() { $this->object->addRouteForInsert('route3', 'mytable'); $this->object->addRouteForinsert('route2'); $this->assertEquals($this->obj2, $this->object->matchRoute('Insert into table (a) values (1)')); $this->assertEquals($this->obj3, $this->object->matchRoute('inSert into mytable (a) values (2)')); } /** * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function testAddRouteForInsertFail() { $this->expectException(\ByJG\AnyDataset\Db\Exception\RouteNotMatchedException::class); $this->object->addRouteForInsert('route3', 'mytable'); $this->object->addRouteForinsert('route2'); $this->object->matchRoute('updata table set a=1'); } public function testAddRouteForUpdate() { $this->object->addRouteForUpdate('route3', 'mytable'); $this->object->addRouteForUpdate('route2'); $this->assertEquals($this->obj2, $this->object->matchRoute('update table set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('update mytable set a=1')); } /** * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function testAddRouteForUpdateFail() { $this->expectException(\ByJG\AnyDataset\Db\Exception\RouteNotMatchedException::class); $this->object->addRouteForUpdate('route3', 'mytable'); $this->object->addRouteForUpdate('route2'); $this->object->matchRoute('delete table where set a=1'); } public function testAddRouteForDelete() { $this->object->addRouteForDelete('route3', 'mytable'); $this->object->addRouteForDelete('route2'); $this->assertEquals($this->obj2, $this->object->matchRoute('delete table where set a=1')); $this->assertEquals($this->obj2, $this->object->matchRoute('delete from table where set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('delete mytable where set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('delete from mytable where set a=1')); } /** * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function testAddRouteForDeleteFail() { $this->expectException(\ByJG\AnyDataset\Db\Exception\RouteNotMatchedException::class); $this->object->addRouteForDelete('route3', 'mytable'); $this->object->addRouteForDelete('route2'); $this->object->matchRoute('update table set a=1'); } public function testAddRouteForTable() { $this->object->addRouteForTable('route3', 'mytable'); $this->assertEquals($this->obj3, $this->object->matchRoute('delete mytable where set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('delete from mytable where set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('update mytable set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('inSert into mytable (a) values (2)')); $this->assertEquals($this->obj3, $this->object->matchRoute('SELECT field1, fields fRom mytable')); } public function testAddRouteForWriteAndRead() { $this->object->addRouteForWrite('route3', 'mytable'); $this->object->addRouteForRead('route2', 'mytable'); $this->assertEquals($this->obj3, $this->object->matchRoute('delete mytable where set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('delete from mytable where set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('update mytable set a=1')); $this->assertEquals($this->obj3, $this->object->matchRoute('inSert into mytable (a) values (2)')); $this->assertEquals($this->obj2, $this->object->matchRoute('SELECT field1, fields fRom mytable')); } public function testAddDefaultRoute() { $this->object->addRouteForWrite('route3', 'mytable'); $this->object->addRouteForRead('route2', 'mytable'); $this->object->addDefaultRoute('route1'); $this->assertEquals($this->obj1, $this->object->matchRoute('SELECT field1, fields fRom othertable')); } public function testAddRouteForFilter() { $this->object->addRouteForFilter('route3', 'id', '3'); $this->assertEquals($this->obj3, $this->object->matchRoute('SELECT field1, fields fRom othertable where id=3')); $this->assertEquals($this->obj3, $this->object->matchRoute('SELECT field1 fRom othertable where id = 3')); $this->assertEquals($this->obj3, $this->object->matchRoute('SELECT field1 fRom othertable where id = \'3\'')); $this->assertEquals($this->obj3, $this->object->matchRoute('SELECT field1, fields fRom othertable where `id` = 3')); } /** * @throws \ByJG\AnyDataset\Db\Exception\RouteNotFoundException * @throws \ByJG\AnyDataset\Db\Exception\RouteNotMatchedException */ public function testAddRouteForFilterFail() { $this->expectException(\ByJG\AnyDataset\Db\Exception\RouteNotMatchedException::class); $this->object->addRouteForFilter('route3', 'id', '3'); $this->object->matchRoute('SELECT field1, fields fRom othertable where id=31'); } } __halt_compiler();----SIGNATURE:----pj4b9lz7ijXwMFmr7OvLbKRCtINv7SLz0XC4vYA+37akC0q5R6Q9jDQoDcRKwGZ5qNop6a2QkgEDL4JCsfRNMHUb3y44+20fu/eshelWWMRobe4Evoel4SY5xKZ4xsC8PFr3IuZgqonOSXGInir+mMH+Z5EJDKJ0fsqAnERzVmdeN/rIud7NeBRsdKw8IkIdIfWysAhLC3GVzmxfLGvE9CKpVNh+dEoUJGOQY0W1b7zMMe7HuKefV/80T/d63l2IE2ZnXI8LzlZk5X6GjR3OZrNWx7rFNKtdfUgZYnMWB3Ibu2QW0r3EaXXBpBYxamVO2F/Fg+PQs7J7AUPEno9c4RivRMKvKKUO2+MhhcZSM1kdrKo7pTM5HBbvcCU6bSggGRbfVOCABeiEOJNc6w+eFYTq8Qa40ArWqs+2iorJv1JLGV2yIyANmVsS7O3o4myHA/AeQ1nAolV9SthAetIerGUYj1zxaEiMAzYOwPMhawxHU0CadD0paxcTA9ZSGNS2aNcVwvgXouesYUaE3622q74vKsU+FHpLLBFLXPBRVDKfOsGYuPNjYMzA5Z286MW6vspo3x9ZHTkaIYBvk3EZ3WQ5B7ffJj2nWhyIkqFQfv92CgYnxrxqFmcAxab9Ys+wK7WH0Co+7DQw+g6UBviDc0/n60/SP1AzN+I5QD5EqsM=----ATTACHMENT:----ODIzMjM4NDk2NzUyMTMzMSA2NjA2NjUwNzkxMjA1MTA5IDk5NzYxNTE1Nzg2MjI5Nw==