1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Symfony package. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ThemeBundle\Tests\Functional; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; |
15
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
16
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
17
|
|
|
|
18
|
|
|
class WebTestCase extends BaseWebTestCase |
19
|
|
|
{ |
20
|
|
|
public static function assertRedirect($response, $location) |
21
|
|
|
{ |
22
|
|
|
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode()); |
23
|
|
|
self::assertEquals('http://localhost'.$location, $response->headers->get('Location')); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function deleteTmpDir($testCase) |
27
|
|
|
{ |
28
|
|
|
if (!file_exists($dir = $this->getTmpDirPath($testCase))) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$fs = new Filesystem(); |
33
|
|
|
$fs->remove($dir); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function getTmpDirPath($testCase) |
37
|
|
|
{ |
38
|
|
|
return sys_get_temp_dir() . '/' . Kernel::VERSION . '/' . $testCase; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected static function getKernelClass() |
42
|
|
|
{ |
43
|
|
|
require_once __DIR__.'/app/AppKernel.php'; |
44
|
|
|
|
45
|
|
|
return 'Sylius\Bundle\ThemeBundle\Tests\Functional\app\AppKernel'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected static function createKernel(array $options = []) |
49
|
|
|
{ |
50
|
|
|
$class = self::getKernelClass(); |
51
|
|
|
|
52
|
|
|
if (!isset($options['test_case'])) { |
53
|
|
|
throw new \InvalidArgumentException('The option "test_case" must be set.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return new $class( |
57
|
|
|
$options['test_case'], |
58
|
|
|
isset($options['root_config']) ? $options['root_config'] : 'config.yml', |
59
|
|
|
isset($options['environment']) ? $options['environment'] : 'frameworkbundletest'.strtolower($options['test_case']), |
60
|
|
|
isset($options['debug']) ? $options['debug'] : true |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|