/**
  * @test
  */
 public function shouldFindModelById()
 {
     $expectedModelClass = 'Payum\\Core\\Tests\\Mocks\\Model\\TestModel';
     $expectedModelId = 123;
     $expectedFoundModel = new TestModel();
     $objectManagerMock = $this->createObjectManagerMock();
     $objectManagerMock->expects($this->once())->method('find')->with($expectedModelClass, $expectedModelId)->will($this->returnValue($expectedFoundModel));
     $storage = new DoctrineStorage($objectManagerMock, 'Payum\\Core\\Tests\\Mocks\\Model\\TestModel');
     $actualModel = $storage->findModelById($expectedModelId);
     $this->assertSame($expectedFoundModel, $actualModel);
 }
 /**
  * @test
  */
 public function shouldFindModelByIdentificator()
 {
     $storage = new DoctrineStorage($this->em, 'Payum\\Core\\Tests\\Mocks\\Entity\\TestModel');
     $model = $storage->createModel();
     $storage->updateModel($model);
     $requestId = $model->getId();
     $this->em->clear();
     $identificator = $storage->getIdentificator($model);
     $foundModel = $storage->findModelByIdentificator($identificator);
     $this->assertInstanceOf('Payum\\Core\\Tests\\Mocks\\Entity\\TestModel', $foundModel);
     $this->assertEquals($requestId, $foundModel->getId());
 }
    /**
     * @test
     */
    public function shouldFindModelByIdentity()
    {
        $storage = new DoctrineStorage(
            $this->dm,
            'Payum\Core\Tests\Mocks\Document\TestModel'
        );

        $model = $storage->create();

        $storage->update($model);

        $requestId = $model->getId();

        $this->dm->clear();

        $identity = $storage->identify($model);

        $foundModel = $storage->find($identity);

        $this->assertInstanceOf('Payum\Core\Tests\Mocks\Document\TestModel', $foundModel);
        $this->assertEquals($requestId, $foundModel->getId());
    }
Esempio n. 4
0
 /**
  * @test
  */
 public function shouldFindByAllIfCriteriaIsEmpty()
 {
     $storage = new DoctrineStorage($this->em, 'Payum\\Core\\Tests\\Mocks\\Entity\\TestModel');
     /** @var TestModel $model */
     $model = $storage->create();
     $model->setCurrency('USD');
     $storage->update($model);
     /** @var TestModel $model */
     $model = $storage->create();
     $model->setCurrency('USD');
     $storage->update($model);
     /** @var TestModel $model */
     $model = $storage->create();
     $model->setCurrency('EUR');
     $storage->update($model);
     $result = $storage->findBy(array());
     $this->assertCount(3, $result);
     $this->assertContainsOnly('Payum\\Core\\Tests\\Mocks\\Entity\\TestModel', $result);
 }