Category : phpunit

My functional test return always code 302 with a redirect to my login page. I looked the official Symfony documentation. I tried the two methods. Symfony documentation Here is my test code <?php namespace AppTestsController; use AppRepositoryUserRepository; use SymfonyBundleFrameworkBundleTestWebTestCase; use SymfonyComponentBrowserKitCookie; use SymfonyComponentHttpFoundationResponse; use SymfonyComponentSecurityCoreAuthenticationTokenUsernamePasswordToken; use SymfonyComponentSecurityGuardTokenPostAuthenticationGuardToken; class SecurityControllerTest extends WebTestCase { private $client = ..

Read more

I’m trying to test my repository. I made BaseLegalRepository class BaseLegalRepository extends TestCase { /** * @var LegalRepository */ protected $repository; public function testAdd(): void { $legal = (new CreateLegalBuilder())->build(); $this->repository->add($legal); $found = $this->repository->get($legal->getId()); $this->assertEquals($legal->getId(), $found->getId()); $this->assertEquals($legal->getName(), $found->getName()); $this->assertEquals($legal->getAddress(), $found->getAddress()); } public function testGet(): void { $this->repository->add($legal = (new CreateLegalBuilder())->build()); $found = $this->repository->get($legal->getId()); $this->assertNotNull($found); $this->assertEquals($legal->getId(), ..

Read more

I have an issue with Panther in a Symfony 4.4 project. The project have LiipFunctionnalTestBundle on it, but for testing JS as well, i wanted to have Panther. I’ve installed Panther, in my composer i’ve "symfony/panther": "^0.8.0"," and i can extends my class with PantherTestCase or use PantherTestCaseTrait to have Panther and Liip (according to ..

Read more

I need to test a function which creates a SimpleXMLElement and converts it to a string with asXML(). For that, I want to check the structure of the file to verify if there is inside "" etc. and 1 to 10 times a particular structure with ”. I wanted to use assertEqualXMLStructure() but it’s deprecated… ..

Read more

I want to do functional tests on my Symfony (5.1) application, this application uses an Active Directory server as a "datas" database (creating , listing , updating datas). I’m using the Symfony ldap component. Code example below may contain typos. Controller class DatasController { /** * @Route("/datas", name="datas") * @IsGranted("ROLE_USER") * * @return Response * ..

Read more

I want to do functional tests on my Symfony (5.1) application, this application uses an Active Directory server as a "datas" database (creating , listing , updating datas). I’m using the Symfony ldap component. Code example below may contain typos. Controller class DatasController { /** * @Route("/datas", name="datas") * @IsGranted("ROLE_USER") * * @return Response * ..

Read more

In the functional tests of a Symfony5.2 application, I added some profiling assertions to check execution time. private static function assertTime(?Profile $profile, int $milliseconds = self::MAX_TIMES) { if (null === $profile) { static::markTestSkipped(‘To test time of this use case, please unable profiling’); } /** @var TimeDataCollector $time */ $time = $profile->getCollector(‘time’); static::assertLessThan( $milliseconds, $time->getDuration(), sprintf( ..

Read more

I have a class like this class MyClass implements ContainerAwareInterface { public function construct(EntityManagerInterface $entityManager) { $this->em = $entityManager; } public function doSomething() { $myService = $this->container->get(‘my.service.defnition.in.services.yaml’); } public function setContainer(ContainerInterface $container = null) { $this->container = $container; } } and the test class with a test method public function testDoSomething() { $manager = new ..

Read more

I have a class like this class MyClass implements ContainerAwareInterface { public function construct(EntityManagerInterface $entityManager) { $this->em = $entityManager; } public function doSomething() { $myService = $this->container->get(‘my.service.defnition.in.services.yaml’); } public function setContainer(ContainerInterface $container = null) { $this->container = $container; } } and the test class with a test method public function testDoSomething() { $manager = new ..

Read more