vendor = new FoodVendor; $this->vendor->setName('Food Vendor'); $this->manager->persist($this->vendor); $this->manager->flush(); } #[Override] public function getEntityClass(): string { return MenuItem::class; } public function testShow(): void { $menuItem = new MenuItem; $menuItem->setName('Testing 1 2'); $this->vendor->addMenuItem($menuItem); $this->manager->persist($this->vendor); $this->manager->persist($menuItem); $this->manager->flush(); $crawler = $this->client->request('GET', "{$this->path}{$menuItem->getId()}"); $idValue = $crawler->filter( '.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)' )->text(); $nameValue = $crawler->filter( '.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)' )->text(); self::assertResponseStatusCodeSame(200); $this->assertEquals($idValue, $menuItem->getId()); $this->assertEquals($nameValue, $menuItem->getName()); } public function testEdit(): void { $menuItem = new MenuItem; $menuItem->setName('Testing 1 2'); $this->vendor->addMenuItem($menuItem); $this->manager->persist($this->vendor); $this->manager->persist($menuItem); $this->manager->flush(); $crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $menuItem->getId())); $nameElem = $crawler->filter('#menu_item_name'); $this->assertEquals( 'Testing 1 2', $nameElem->attr('value') ); $this->client->submitForm('Update', [ 'menu_item[name]' => 'Testing-1', ]); self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId())); } public function testDelete(): void { $menuItem = new MenuItem; $menuItem->setName('Testing 1 2'); $this->vendor->addMenuItem($menuItem); $this->manager->persist($this->vendor); $this->manager->persist($menuItem); $order = new FoodOrder(); $order->setFoodVendor($this->vendor); $this->manager->persist($order); $this->manager->flush(); $this->assertFalse($menuItem->isDeleted()); $this->client->request('GET', "{$this->path}{$menuItem->getId()}"); $this->client->submitForm('Delete', []); $menuItem = $this->repository->find($menuItem->getId()); $this->assertTrue($menuItem->isDeleted()); $crawler = $this->client->request('GET', '/order/item/new/' . $order->getId()); $count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')->children()->count(); $this->assertSame(0, $count); $this->assertResponseIsSuccessful(); } }