I setup this environment to distinguish it from prod
and from dev
.
- a
SYMFONY_ENV=travis
environment variable setup in Travis - a
config_travis.yml
that contains my configuration for the Travis env - a
app_travis.php
which specify the environment to load - a
.travis.yml
:
language: php
php:
- "7.2.17"
services:
- mysql
install:
- composer install --no-interaction
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('${MYSQL_PASSWORD}') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root
- ./bin/console doctrine:database:create --env=travis
- ./bin/console doctrine:migration:migrate --env=travis --no-interaction
script:
- ./vendor/bin/simple-phpunit
I can layout project tree if need be.
Some examples of tests I’m running:
UserTest.php
which tests the User.php
model:
<?php
namespace Tests\AppBundle\Entity;
use AppBundle\Entity\User;
use PHPUnit\Framework\TestCase;
use AppBundle\Entity\Responsibility;
class UserTest extends TestCase
{
public function testId()
{
$user = new User();
$id = $user->getId();
$this->assertEquals(-1, $id);
}
}
LoginControllerTest.php
which tests the LoginController.php
controller:
<?php
namespace Tests\AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpFoundation\Response;
class LoginControllerTest extends WebTestCase
{
/*
* Test the login form
* Logins with (admin, password : a)
*/
public function testLogin()
{
// Create a new client to browse the app
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET ");
// Get the form
$form = $crawler->selectButton('Connexion')->form();
// Fill the login form input
$form['_username']->setValue('admin');
$form['_password']->setValue('a');
// Send the form
$client->submit($form);
$crawler = $client->followRedirect();
$this->assertContains(
'Bienvenue admin.' ,
$client->getResponse()->getContent()
);
return array($client,$crawler);
}
}
My problem is: all the command run into the travis
environment, except the unit tests. I want to be able to run the unit tests in dev
env on my computer but in travis
env in the Travis container, in other words locally.
How can I setup my PHPUnit so that it can run in travis
environment and use my config_travis.yml
file?
-SU