WebTestCase.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
  11. use Symfony\Component\HttpKernel\Util\Filesystem;
  12. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
  13. class WebTestCase extends BaseWebTestCase
  14. {
  15. static public function assertRedirect($response, $location)
  16. {
  17. self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode());
  18. self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
  19. }
  20. protected function setUp()
  21. {
  22. if (!class_exists('Twig_Environment')) {
  23. $this->markTestSkipped('Twig is not available.');
  24. }
  25. parent::setUp();
  26. }
  27. protected function deleteTmpDir($testCase)
  28. {
  29. if (!file_exists($dir = sys_get_temp_dir().'/'.$testCase)) {
  30. return;
  31. }
  32. $fs = new Filesystem();
  33. $fs->remove($dir);
  34. }
  35. static protected function getKernelClass()
  36. {
  37. require_once __DIR__.'/app/AppKernel.php';
  38. return 'Symfony\Bundle\FrameworkBundle\Tests\Functional\AppKernel';
  39. }
  40. static protected function createKernel(array $options = array())
  41. {
  42. $class = self::getKernelClass();
  43. if (!isset($options['test_case'])) {
  44. throw new \InvalidArgumentException('The option "test_case" must be set.');
  45. }
  46. return new $class(
  47. $options['test_case'],
  48. isset($options['root_config']) ? $options['root_config'] : 'config.yml',
  49. isset($options['environment']) ? $options['environment'] : 'frameworkbundletest',
  50. isset($options['debug']) ? $options['debug'] : true
  51. );
  52. }
  53. }