WebTestCase.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
  11. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
  12. use Symfony\Component\Filesystem\Filesystem;
  13. class WebTestCase extends BaseWebTestCase
  14. {
  15. public static 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. public static function setUpBeforeClass()
  21. {
  22. static::deleteTmpDir();
  23. }
  24. public static function tearDownAfterClass()
  25. {
  26. static::deleteTmpDir();
  27. }
  28. protected static function deleteTmpDir()
  29. {
  30. if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) {
  31. return;
  32. }
  33. $fs = new Filesystem();
  34. $fs->remove($dir);
  35. }
  36. protected static function getKernelClass()
  37. {
  38. require_once __DIR__.'/app/AppKernel.php';
  39. return 'Symfony\Bundle\FrameworkBundle\Tests\Functional\app\AppKernel';
  40. }
  41. protected static function createKernel(array $options = array())
  42. {
  43. $class = self::getKernelClass();
  44. if (!isset($options['test_case'])) {
  45. throw new \InvalidArgumentException('The option "test_case" must be set.');
  46. }
  47. return new $class(
  48. static::getVarDir(),
  49. $options['test_case'],
  50. isset($options['root_config']) ? $options['root_config'] : 'config.yml',
  51. isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']),
  52. isset($options['debug']) ? $options['debug'] : true
  53. );
  54. }
  55. protected static function getVarDir()
  56. {
  57. return substr(strrchr(\get_called_class(), '\\'), 1);
  58. }
  59. }