Skip to content

Instantly share code, notes, and snippets.

@garak
Forked from giorrrgio/WebTestCase.php
Last active Dec 19, 2015
Embed
What would you like to do?
<?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