/**
  * @param float $discount
  */
 public function apply($discount)
 {
     $this->entityManager->transactional(function () use($discount) {
         foreach ($this->items->findAll() as $item) {
             $item->applyDiscount($discount);
         }
     });
     $this->entityManager->clear();
 }
 /**
  * @test
  * @dataProvider items
  */
 public function reverting_transaction()
 {
     $this->givenDatabaseIsClear();
     $this->getEntityManager()->beginTransaction();
     $this->add(new Teapot('brand-new-teapot', 10.0));
     $this->add(new Phone('amazing-phone', 400.0));
     $items = ItemRepository::create($this->getEntityManager())->paginate(1, 2);
     $this->assertCount(2, $items);
     $this->getEntityManager()->rollback();
 }
 protected function givenSqliteDatabaseWasConnected()
 {
     $this->entityManager = EntityManagerFactory::create(SqliteConfig::getParams());
     $this->items = ItemRepository::create($this->getEntityManager());
 }
 /**
  * @test
  * @expectedException \InvalidArgumentException
  * @dataProvider invalidArguments
  */
 public function it_fails_with_invalid_arguments($page, $itemsPerPage)
 {
     $this->givenDatabaseIsClear();
     $this->add(new Teapot('new-teapot', 100.3));
     ItemRepository::create($this->getEntityManager())->paginate($page, $itemsPerPage);
 }