public function testDbTableAbstractFactory__invokeIfConfigExist()
 {
     $createStatementStr = 'CREATE TEMPORARY TABLE IF NOT EXISTS test_res_tablle (id INT)';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
     $container = (include 'config/container.php');
     $requestedName = 'testDbTable';
     $result = $this->object->__invoke($container, $requestedName);
     $this->assertSame('zaboy\\rest\\DataStore\\DbTable', get_class($result));
 }
 public function testTableGatewayAbstractFactory__invokeIfTableAbsent()
 {
     $createStatementStr = 'CREATE TABLE IF NOT EXISTS tbl_name_which_exist (id INT)';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
     $requestedName = 'tbl_name_which_exist';
     $result = $this->object->__invoke($this->container, $requestedName);
     $this->assertSame('Zend\\Db\\TableGateway\\TableGateway', get_class($result));
     $createStatementStr = 'DROP TABLE IF EXISTS tbl_name_which_exist';
     $createStatement = $this->adapter->query($createStatementStr);
     $createStatement->execute();
 }
 public function testResponseEncoder__invoke()
 {
     $rowset = [1 => 'a', 2 => 'b'];
     $request = $this->request->withAttribute('Response-Body', $rowset);
     $contentRangeHeader = 'items 0-0/1';
     $response = $this->response->withHeader('Content-Range', $contentRangeHeader);
     $response = $response->withStatus(555);
     $response = $this->object->__invoke($request, $response, $this->next);
     $this->assertEquals($response->getBody()->__toString(), '{"1":"a","2":"b"}');
     $this->assertEquals($response->getStatusCode(), 555);
     $headers = $response->getHeaders();
     $this->assertEquals($headers['Content-Range'][0], "items 0-0/1");
     $this->assertEquals($headers['content-type'][0], "application/json");
 }
 public function testReturner__invoke()
 {
     $this->request = new ServerRequest([], [], '/foo');
     $returned = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returned->getAttribute('Resource-Name'), 'foo');
     $this->assertSame($returned->getAttribute('id'), null);
     $this->request = new ServerRequest([], [], '/foo?a=3');
     $returned = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returned->getAttribute('Resource-Name'), 'foo');
     $this->assertSame($returned->getAttribute('id'), null);
     $this->request = new ServerRequest([], [], 'foo/');
     $returned = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returned->getAttribute('Resource-Name'), 'foo');
     $this->assertSame($returned->getAttribute('id'), null);
     $this->request = new ServerRequest([], [], '/foo/1662');
     $returned = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returned->getAttribute('Resource-Name'), 'foo');
     $this->assertSame($returned->getAttribute('id'), '1662');
     $this->request = new ServerRequest([], [], '/foo/1t3?F=r');
     $returned = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returned->getAttribute('Resource-Name'), 'foo');
     $this->assertSame($returned->getAttribute('id'), '1t3');
     $this->request = new ServerRequest([], [], 'foo/d_f-g1?');
     $returned = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returned->getAttribute('Resource-Name'), 'foo');
     $this->assertSame($returned->getAttribute('id'), 'd_f-g1');
 }
Exemplo n.º 5
0
 public function testResourceResolver__invokeResourceName5()
 {
     $this->request = new ServerRequest([], [], '/');
     $this->next = function ($req, $resp) {
         return $req;
     };
     $returnedResponse = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame($returnedResponse->getAttribute('Resource-Name'), null);
     $this->assertSame($returnedResponse->getAttribute('Primary-Key-Value'), null);
 }
Exemplo n.º 6
0
 public function testDataStoreMemory__invoke()
 {
     $returnedResponse = $this->object->__invoke($this->request, $this->response, $this->next);
     $this->assertSame(get_class($returnedResponse->getAttribute('memoryStore')), 'zaboy\\rest\\DataStore\\Memory');
 }