Category : unit-testing

I would like to write a unit test for method when internal MockClass will call method once and that will return Generator. $em = $this->createMock(EntityManagerInterface::class); $builder = $this->createMock(ArticleBuilder::class); $massiveInsert = new MassiveInsert($em); $builder->expects(($this->once()))->method(‘createMany’)->willReturn(new Generator()); $builder->expects(($this->exactly(3)))->method(‘create’)->willReturn(Article::class); $massiveInsert->insertMany($builder, [‘test’, ‘test1’, ‘test2’]); So far I wrote something like this. But I have following error: Error: The "Generator" class ..

Read more

I’m using a Symfony 5.2 installation installed as a skeleton project and running on PHP 7.4:latest I am using SymfonyContractsCacheTagAwareCacheInterface as an auto-wired constructor injected dependency in a class. I want to cache the open id response I fetch from the configuration endpoint: $config = $this->cachePool->get( ‘openid-config’, function (ItemInterface $item) { $item->expiresAfter(self::CACHE_TIME_SECONDS); $webContent = file_get_contents($this->openIdConfigurationUrl); ..

Read more

Im serializeing an object that contains DateTimeImmutable fields (creadted_ad, updated_at). When using a serialization object as dependecnyc injection it’s all good. But then i’m writing an unit tests and my first problem is that serializer doesn’t see the @Groups (after serialization there are fields taht are restricted by @Group annotation,btw. its working well with symfony ..

Read more

I’ve been working on a grid bundle for Symfony. The bundle receives a Symfony Entity and based on that, it renders a gridview. something like this: class IndexController extends AbstractController { public function __construct(GridBuilder $grid, BookGrid $userGrid) { $this->grid = $grid; $this->userGrid = $userGrid; } /** * @Route("/") */ public function index() { return $this->render(‘index.html.twig’, ..

Read more

public function testTest(){ $this->assertEquals("1", "2"); } This code give error PHPUnit 9.3.10 by Sebastian Bergmann and contributors. E 1 / 1 (100%) Time: 00:01.793, Memory: 8.00 MB There was 1 error: 1) MbArticleBundleTestsControllerArticleControllerAdminTest::testTest PHPUnitFrameworkException: 2020-09-25T13:18:08+02:00 [critical] Uncaught PHP Exception Exception: "Serialization of ‘Closure’ is not allowed" at C:UsersUSERAppDataLocalTempPHP7D5C.tmp line 275 2020-09-25T13:18:08+02:00 [critical] Exception thrown when ..

Read more

In my Symfony project, I want to do this task : You’ll need to create a new test class: tests/AppBundle/Command/EntitiesAndAnnotationsCheckCommandTest.php This test class will have a test that will run the doctrine:schema:update –dump-sql command. We need to test that this command ends up properly (does not ends with error) Also check that the command output ..

Read more