Esempio n. 1
0
 /**
  * Permet de tester la création de réponse via la factory
  */
 public function testCreateResponse()
 {
     $response = Response::create();
     $this->assertInstanceOf(ResponseContent::class, $response);
     $response = Response::string('view');
     $this->assertInstanceOf(StringMessage::class, $response->view);
     $response = Response::json(['id' => 1]);
     $this->assertInstanceOf(JsonMessage::class, $response->view);
     $response = Response::text('');
     $this->assertInstanceOf(TextMessage::class, $response->view);
     $response = Response::html('');
     $this->assertInstanceOf(HtmlMessage::class, $response->view);
 }
Esempio n. 2
0
 public function testRender()
 {
     Config::add(__DIR__ . '/../Test/test.php', 'app');
     $string = Response::string('view');
     $this->assertEquals('view', $string->view->render());
     $json = Response::json(['id' => 1]);
     $this->assertEquals('{"id":1}', $json->view->render());
     $text = Response::html('test', 'a', ['id' => 1], ['b.js']);
     $this->assertEquals('<h1>a</h1><p>1</p><script src="b.js"></script>', $text->view->render());
     $html = Response::text('salut');
     $catched = false;
     try {
         $html->view->render();
     } catch (InvalidArgumentException $e) {
         $this->assertEquals('View [salut] not found.', $e->getMessage());
         $catched = true;
     }
     $this->assertTrue($catched);
 }