Skip to content

Instantly share code, notes, and snippets.

@garak
Forked from giorrrgio/WebTestCase.php
Last active December 19, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garak/5926148 to your computer and use it in GitHub Desktop.
Save garak/5926148 to your computer and use it in GitHub Desktop.
<?php
namespace MyNamespace\CoreBundle\Test;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase;
use Symfony\Component\Process\Process;
abstract class WebTestCase extends SymfonyWebTestCase
{
protected $container;
// feel free to adapt this method, main point is that you get container in $this->container
protected function init()
{
$kernel = static::createKernel();
$kernel->boot();
$this->container = $kernel->getContainer();
}
protected function saveOutput(Client $client, $domain = null, $browser = 'firefox')
{
$path = $this->container->get('kernel')->getRootDir() . '/../web/test_out.html';
file_put_contents($path, $client->getResponse()->getContent());
if (!is_null($domain)) {
$process = new Process($browser . ' "'.$domain.'/test_out.html"');
$process->run();
}
}
}
<?php
namespace MyNamespace\CoreBundle\Test;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase;
use Symfony\Component\Process\Process;
abstract class WebTestCase extends SymfonyWebTestCase
{
protected function saveOutput(Client $client, $domain = null, $delete = true, $browser = 'firefox')
{
$path = $this->container->get('kernel')->getRootDir() . '/../web/test_out.html';
file_put_contents($path, $client->getResponse()->getContent());
if (!is_null($domain)) {
$process = new Process($browser . ' "'.$domain.'/test_out.html"');
$process->start();
sleep(1);
if ($delete) {
unlink($path);
}
}
}
}
<?php
namespace MyNamespace\CoreBundle\Test;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase;
use Symfony\Component\Process\Process;
abstract class WebTestCase extends SymfonyWebTestCase
{
protected function saveOutput(Client $client, $domain = null, $delete = true, $browser = 'firefox')
{
$path = $this->container->get('kernel')->getRootDir() . '/../web/test_out.html';
file_put_contents($path, $client->getResponse()->getContent());
if (!is_null($domain)) {
$process = new Process($browser . ' "'.$domain.'/test_out.html"');
$process->run(function() use($path, $delete) {
if ($delete) {
unlink($path);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment