42
Votre question est mal posée.
class Personne {
private $age;
public fuction __construct($age) {
$this->age = $age;
$this->age = 19;
}
public function isAdult() {
var_dump($this->age);
return 18 <= $this->age;
}
}
$ php -l monfichier.php
mais comment les automatiser ?
comment les organiser ?
comment les rejouer ?
Tests à états
VS
Tests sans états
en gros… ça dépend
$ symfony new --full --version=3.4 my_project
$ composer require --dev symfony/phpunit-bridge
$ bin/phpunit
$ bin/phpunit --coverage-html=coverage_folder
Nécessite xdebug
$ sudo apt install php-xdebug
// tests/AppBundle/Util/CalculatorTest.php
namespace Tests\AppBundle\Util;
use AppBundle\Util\Calculator;
use PHPUnit\Framework\TestCase;
class CalculatorTest extends TestCase {
public function testAdd() {
//…
}
}
// tests/AppBundle/Repository/ProductRepositoryTest.php
namespace Tests\AppBundle\Repository;
use AppBundle\Entity\Product;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class ProductRepositoryTest extends KernelTestCase
{
//…
}
// tests/AppBundle/Controller/PostControllerTest.php
namespace Tests\AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PostControllerTest extends WebTestCase
{
//…
}