Beispiel #1
0
 public function testIndexReferences()
 {
     $this->hive->configuration['security'] = false;
     $this->hive->resource('Hive\\Tests\\Models\\User');
     $user = new User();
     $user->email = '*****@*****.**';
     $user->name = 'Test';
     $post1 = new Post();
     $post1->title = 'Test Title';
     $post1->body = 'Test body';
     $post1->user = $user;
     $post2 = new Post();
     $post2->title = 'Test Title 2';
     $post2->body = 'Test body 2';
     $post2->user = $user;
     $this->hive->dm->persist($user);
     $this->hive->dm->persist($post1);
     $this->hive->dm->persist($post2);
     $this->hive->dm->persist($user);
     $this->hive->dm->flush();
     /** @var Request $request */
     $request = MockRequestFactory::create('/users/' . $user->id . '/posts', 'GET');
     $request->headers()['content-type'] = 'application/json';
     $response = new Response();
     $this->hive->api($request, $response, false);
     $data = json_decode($response->body(), true);
     $this->assertEquals(200, $response->code());
     $this->assertNotEmpty($data);
     $this->assertEquals($post2->title, $data[0]['title']);
     $this->assertEquals($post2->body, $data[0]['body']);
     $this->assertEquals($post1->title, $data[1]['title']);
     $this->assertEquals($post1->body, $data[1]['body']);
     $this->hive->dm->remove($post1);
     $this->hive->dm->remove($post2);
     $this->hive->dm->remove($user);
     $this->hive->dm->flush();
 }
Beispiel #2
0
 /**
  * Method for initializing a PromisesTrait object with the Closures
  *
  * @param PromisesTrait|Hive|Resource $promisesTrait
  * @return PromisesTrait|Hive|Resource
  */
 protected function initPromises($promisesTrait)
 {
     return $promisesTrait->findOne($this->createFindOneClosure())->findMany($this->createFindManyClosure())->renderResult($this->createRenderResultClosure())->allowRequest($this->createAllowRequestClosure());
 }