-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathFakeControllerTest.php
More file actions
83 lines (58 loc) · 2.63 KB
/
Copy pathFakeControllerTest.php
File metadata and controls
83 lines (58 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Liuggio\ExcelBundle\Tests\Controller;
use Liuggio\ExcelBundle\Tests\app\AppKernel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FakeControllerTest extends WebTestCase
{
public function testStreamAction()
{
$client = static::createClient();
$client->request(Request::METHOD_GET, '/fake/stream');
$client->getResponse()->sendContent();
$content = ob_get_contents();
ob_clean();
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode(), $client->getResponse()->getContent());
$this->assertStringStartsWith('attachment;filename=', $client->getResponse()->headers->get('content-disposition'));
$this->assertNotEmpty($content, 'Response should not be empty');
$this->assertNotNull($content, 'Response should not be null');
}
public function testReaderAction()
{
$client = static::createClient();
$client->request(Request::METHOD_GET, '/fake/reader');
$client->getResponse()->sendContent();
$content = ob_get_contents();
ob_clean();
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode(), $client->getResponse()->getContent());
$this->assertEquals('Hello world!', $client->getResponse()->getContent());
$this->assertNotEmpty($content, 'Response should not be empty');
$this->assertNotNull($content, 'Response should not be null');
}
public function testSaveAction()
{
$client = static::createClient();
$client->request(Request::METHOD_GET, '/fake/store');
$this->assertEquals(Response::HTTP_CREATED, $client->getResponse()->getStatusCode(), $client->getResponse()->getContent());
$content = $client->getResponse()->getContent();
$this->assertStringEndsWith('.xls', $content);
$this->assertFileExists($content, sprintf('file %s should exist', $content));
}
public function testReadAndSaveAction()
{
$client = static::createClient();
$client->request(Request::METHOD_GET, '/fake/read');
$this->assertEquals(Response::HTTP_CREATED, $client->getResponse()->getStatusCode(), $client->getResponse()->getContent());
$content = $client->getResponse()->getContent();
$this->assertStringEndsWith('.xls', $content);
$this->assertFileExists($content, sprintf('file %s should exist', $content));
}
/**
* @inheritdoc
*/
protected static function getKernelClass()
{
return AppKernel::class;
}
}