public function testCreate()
 {
     $actionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Indexer\\ActionInterface', [], '', false);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Indexer\\ActionInterface', [])->willReturn($actionInterfaceMock);
     $this->model->create('Magento\\Framework\\Indexer\\ActionInterface');
     $this->assertInstanceOf('Magento\\Framework\\Indexer\\ActionInterface', $actionInterfaceMock);
 }
 protected function setUp()
 {
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->objectManagerMock = $this->getMockBuilder('\\Magento\\Framework\\ObjectManagerInterface')->disableOriginalConstructor()->getMock();
     $this->objectManagerMock->expects($this->any())->method('create')->willReturnCallback(function ($className) use($objectManager) {
         return $objectManager->getObject($className);
     });
     /** @var \Magento\Framework\Reflection\TypeProcessor $typeProcessor */
     $typeProcessor = $objectManager->getObject('Magento\\Framework\\Reflection\\TypeProcessor');
     $cache = $this->getMockBuilder('Magento\\Framework\\App\\Cache\\Type\\Reflection')->disableOriginalConstructor()->getMock();
     $cache->expects($this->any())->method('load')->willReturn(false);
     $this->customAttributeTypeLocator = $this->getMockBuilder('Magento\\Eav\\Model\\EavCustomAttributeTypeLocator')->disableOriginalConstructor()->getMock();
     /** @var \Magento\Framework\Api\AttributeDataBuilder */
     $this->attributeValueFactoryMock = $this->getMockBuilder('Magento\\Framework\\Api\\AttributeValueFactory')->disableOriginalConstructor()->getMock();
     $this->attributeValueFactoryMock->expects($this->any())->method('create')->willReturnCallback(function () use($objectManager) {
         return $objectManager->getObject('Magento\\Framework\\Api\\AttributeValue');
     });
     $this->fieldNamer = $this->getMockBuilder('Magento\\Framework\\Reflection\\FieldNamer')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->methodsMap = $objectManager->getObject('Magento\\Framework\\Reflection\\MethodsMap', ['cache' => $cache, 'typeProcessor' => $typeProcessor, 'attributeTypeResolver' => $this->attributeValueFactoryMock->create(), 'fieldNamer' => $this->fieldNamer]);
     $this->serviceInputProcessor = $objectManager->getObject('Magento\\Framework\\Webapi\\ServiceInputProcessor', ['typeProcessor' => $typeProcessor, 'objectManager' => $this->objectManagerMock, 'customAttributeTypeLocator' => $this->customAttributeTypeLocator, 'attributeValueFactory' => $this->attributeValueFactoryMock, 'methodsMap' => $this->methodsMap]);
     /** @var \Magento\Framework\Reflection\NameFinder $nameFinder */
     $nameFinder = $objectManager->getObject('\\Magento\\Framework\\Reflection\\NameFinder');
     $serviceInputProcessorReflection = new \ReflectionClass(get_class($this->serviceInputProcessor));
     $typeResolverReflection = $serviceInputProcessorReflection->getProperty('nameFinder');
     $typeResolverReflection->setAccessible(true);
     $typeResolverReflection->setValue($this->serviceInputProcessor, $nameFinder);
 }
Example #3
0
 public function testCreate()
 {
     $this->builder->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $this->factory->expects($this->once())->method('createItem')->with($this->identicalTo($name))->will($this->returnValue($item = $this->createItemMock()));
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->identicalTo(MenuBuilderEvents::BUILD), $this->callback(function (MenuBuilderEvent $event) use($item) {
         return $event->getFactory() === $this->factory && $event->getItem() === $item;
     }));
     $this->assertSame($item, $this->builder->create());
 }
 public function testSaveWithExtra()
 {
     $log = $this->subject->create();
     $log->setExtra(['job_ticket']);
     $this->entityManager->expects($this->once())->method('persist')->with($this->callback(function (LogInterface $value) use($log) {
         $extra = $value->getExtra();
         return $log === $value && !isset($extra['job_ticket']);
     }));
     $this->subject->save($log);
 }
 /**
  * @param string                 $type
  * @param null                   $parameters
  * @param ScheduleInterface|null $schedule
  * @dataProvider provideArguments
  */
 public function testCreate($type, $parameters = null, $schedule = null)
 {
     $this->subject->expects($this->any())->method('getClass')->willReturn(Job::class);
     $entity = $this->subject->create($type, $parameters, $schedule);
     $this->assertInstanceOf(Job::class, $entity);
     $this->assertEquals($type, $entity->getType());
     if (!is_null($schedule)) {
         $this->assertContains($schedule, $entity->getSchedules());
     }
 }
 public function testCreate()
 {
     $statement = $this->createDbalStatementMock();
     $statement->expects($this->once())->method('rowCount')->will($this->returnValue(1));
     $this->dbalMock->expects($this->once())->method('prepare')->with($this->anything())->will($this->returnValue($statement));
     $spiCreateStruct = new SPIBinaryFileCreateStruct();
     $spiCreateStruct->id = 'prefix/my/file.png';
     $spiCreateStruct->mimeType = 'image/png';
     $spiCreateStruct->size = 123;
     $spiCreateStruct->mtime = 1307155200;
     $this->assertInstanceOf('eZ\\Publish\\SPI\\IO\\BinaryFile', $this->handler->create($spiCreateStruct));
 }
 public function testCreateOverwritesIfExists()
 {
     $stream = fopen('php://memory', 'rb');
     $spiBinaryFileCreateStruct = new SPIBinaryFileCreateStruct();
     $spiBinaryFileCreateStruct->id = 'prefix/my/file.png';
     $spiBinaryFileCreateStruct->mimeType = 'image/png';
     $spiBinaryFileCreateStruct->size = 123;
     $spiBinaryFileCreateStruct->mtime = 1307155200;
     $spiBinaryFileCreateStruct->setInputStream($stream);
     $this->filesystem->expects($this->once())->method('writeStream')->with($this->equalTo($spiBinaryFileCreateStruct->id), $this->equalTo($stream), $this->equalTo(array('mimetype' => 'image/png', 'visibility' => 'public')))->will($this->throwException(new FileExistsException('prefix/my/file.png')));
     $this->filesystem->expects($this->once())->method('updateStream')->with($this->equalTo($spiBinaryFileCreateStruct->id), $this->equalTo($stream), $this->equalTo(array('mimetype' => 'image/png', 'visibility' => 'public')));
     $this->handler->create($spiBinaryFileCreateStruct);
 }
 public function testCreate()
 {
     // good example of bad responsibilities... since create also loads, we test the same thing twice
     $spiCreateStruct = new SPIBinaryFileCreateStruct();
     $spiCreateStruct->id = 'prefix/my/file.png';
     $spiCreateStruct->size = 123;
     $spiCreateStruct->mtime = new DateTime('@1307155200');
     $expectedSpiBinaryFile = new SPIBinaryFile();
     $expectedSpiBinaryFile->id = 'prefix/my/file.png';
     $expectedSpiBinaryFile->size = 123;
     $expectedSpiBinaryFile->mtime = new DateTime('@1307155200');
     $this->filesystem->expects($this->once())->method('getMetadata')->with($spiCreateStruct->id)->will($this->returnValue(array('timestamp' => 1307155200, 'size' => 123)));
     $spiBinaryFile = $this->handler->create($spiCreateStruct);
     $this->assertInstanceOf('eZ\\Publish\\SPI\\IO\\BinaryFile', $spiBinaryFile);
     $this->assertEquals($expectedSpiBinaryFile, $spiBinaryFile);
 }
Example #9
0
 public function testCreate()
 {
     $categorySdo = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Category')->disableOriginalConstructor()->getMock();
     $this->categoryMapper->expects($this->any())->method('toModel')->with($categorySdo)->will($this->returnValue($this->category));
     $this->category->expects($this->once())->method('validate')->will($this->returnValue([]));
     $this->category->expects($this->once())->method('save');
     $parentCategory = $this->getMockBuilder('Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->getMock();
     $parentCategory->expects($this->any())->method('load')->will($this->returnSelf());
     $parentCategory->expects($this->any())->method('__call')->with('getPath')->will($this->returnValue('1\\2'));
     $categoryFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\CategoryFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $categoryFactory->expects($this->any())->method('create')->will($this->returnValue($parentCategory));
     $parentId = 1;
     $storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getRootCategoryId', '__sleep', '__wakeup'], [], '', false);
     $store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($parentId));
     $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $this->model = (new ObjectManager($this))->getObject('Magento\\Catalog\\Service\\V1\\Category\\WriteService', ['categoryFactory' => $categoryFactory, 'categoryMapper' => $this->categoryMapper, 'storeManager' => $storeManager]);
     $this->model->create($categorySdo);
 }
Example #10
0
 /**
  * @param array $customerData
  * @param int|null $origId
  * @dataProvider welcomeEmailNotCalledDataProvider
  */
 public function testSendWelcomeEmailNotCalled(array $customerData, $origId)
 {
     $this->_customer->expects($this->never())->method('sendNewAccountEmail');
     $this->_customer->expects($this->once())->method('save');
     $this->_customer->expects($this->any())->method('getOrigData')->will($this->returnValue($origId));
     if (array_key_exists('confirmation', $customerData)) {
         $this->_customer->expects($this->any())->method('getConfirmation')->will($this->returnValue($customerData['confirmation']));
     }
     $this->assertInstanceOf('Mage_Customer_Model_Customer', $this->_service->create($customerData));
 }
 /**
  * @covers ::create()
  */
 public function testCreate()
 {
     $language_manager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->container->set('language_manager', $language_manager);
     $this->container->set('entity.manager', $this->entityManager);
     $this->container->set('module_handler', $this->moduleHandler);
     $entity = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')->disableOriginalConstructor()->setMethods(array('id'))->getMockForAbstractClass();
     $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->atLeastOnce())->method('getClass')->will($this->returnValue(get_class($entity)));
     $this->entityType->expects($this->atLeastOnce())->method('getKeys')->will($this->returnValue(array('id' => 'id')));
     // ContentEntityStorageBase iterates over the entity which calls this method
     // internally in ContentEntityBase::getProperties().
     $this->entityManager->expects($this->once())->method('getFieldDefinitions')->will($this->returnValue(array()));
     $this->entityType->expects($this->atLeastOnce())->method('isRevisionable')->will($this->returnValue(FALSE));
     $this->entityManager->expects($this->atLeastOnce())->method('getDefinition')->with($this->entityType->id())->will($this->returnValue($this->entityType));
     $this->setUpEntityStorage();
     $entity = $this->entityStorage->create();
     $entity->expects($this->atLeastOnce())->method('id')->will($this->returnValue('foo'));
     $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity);
     $this->assertSame('foo', $entity->id());
     $this->assertTrue($entity->isNew());
 }
 public function testCreate()
 {
     $subscriptionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\SubscriptionInterface', [], '', false);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Mview\\View\\SubscriptionInterface', ['some_data'])->will($this->returnValue($subscriptionInterfaceMock));
     $this->assertEquals($subscriptionInterfaceMock, $this->model->create(['some_data']));
 }
 /**
  * @expectedException \LogicException
  */
 public function testCreateLogicException()
 {
     $this->scopeConfig->expects($this->once())->method('getValue')->with($this->equalTo('some_path'), $this->equalTo('some_scopeType'))->will($this->returnValue('Class'));
     $this->adapterFactory->create(['input']);
 }
 public function testCreate()
 {
     $this->subject->expects($this->any())->method('getClass')->will($this->returnValue('Abc\\Bundle\\FileDistributionBundle\\Entity\\Definition'));
     $entity = $this->subject->create();
     $this->assertInstanceOf('Abc\\Bundle\\FileDistributionBundle\\Entity\\Definition', $entity);
 }
Example #15
0
 public function testCreate()
 {
     $this->subject->expects($this->once())->method('getClass')->will($this->returnValue(Log::class));
     $schedule = $this->subject->create();
     $this->assertInstanceOf(Log::class, $schedule);
 }
Example #16
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testCreateExceptionThrown()
 {
     $adapter = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->objectManager->expects($this->once())->method('create')->with($this->equalTo('ClassName'), $this->equalTo(['input']))->will($this->returnValue($adapter));
     $this->adapterFactory->create(['input']);
 }