public function setUp() { $this->dm = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->dm->expects($this->once())->method('find')->will($this->returnValue(new \stdClass())); $this->defaultModelManager = $this->getMockBuilder('Sonata\\DoctrinePHPCRAdminBundle\\Model\\ModelManager')->disableOriginalConstructor()->getMock(); $this->translator = $this->getMockBuilder('Symfony\\Component\\Translation\\TranslatorInterface')->disableOriginalConstructor()->getMock(); $this->assetHelper = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock(); $this->pool = $this->getMockBuilder('Sonata\\AdminBundle\\Admin\\Pool')->disableOriginalConstructor()->getMock(); }
/** * Create the guesser for this test. * * @return GuesserInterface */ protected function createGuesser() { $this->registry = $this->getMockBuilder('\\Doctrine\\Bundle\\PHPCRBundle\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $this->manager = $this->getMockBuilder('\\Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->metadata = $this->getMockBuilder('\\Doctrine\\ODM\\PHPCR\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getManagerForClass')->with($this->equalTo('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Unit\\Sitemap\\LastModifiedGuesserTest'))->will($this->returnValue($this->manager)); $this->manager->expects($this->any())->method('getClassMetadata')->with($this->equalTo('Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Unit\\Sitemap\\LastModifiedGuesserTest'))->will($this->returnValue($this->metadata)); $this->metadata->expects($this->any())->method('getMixins')->will($this->returnValue(array('mix:lastModified'))); $this->metadata->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('lastModified'))); $this->metadata->expects($this->any())->method('getFieldMapping')->with($this->equalTo('lastModified'))->will($this->returnValue(array('property' => 'jcr:lastModified'))); $this->metadata->expects($this->any())->method('getFieldValue')->with($this->equalTo($this), $this->equalTo('lastModified'))->will($this->returnValue(new \DateTime('2016-07-06', new \DateTimeZone('Europe/Berlin')))); return new LastModifiedGuesser($this->registry); }
protected function setUp() { if (!interface_exists('Doctrine\\Common\\Persistence\\ManagerRegistry')) { $this->markTestSkipped('Doctrine Common is not present'); } if (!class_exists('Doctrine\\ODM\\PHPCR\\DocumentManager')) { $this->markTestSkipped('Doctrine PHPCR is not present'); } $this->registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $this->manager = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->manager)); $this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository', array('customQueryBuilderCreator', 'createQueryBuilder', 'find', 'findAll', 'findBy', 'findOneBy', 'getClassName')); $this->manager->expects($this->any())->method('getRepository')->with($this->objectClass)->will($this->returnValue($this->repository)); }
/** * URL without locale, set available translations. */ public function testAvailableTranslations() { $this->routeMock->expects($this->once())->method('getId')->will($this->returnValue('/cms/simple/something')); $this->dmMock->expects($this->once())->method('isDocumentTranslatable')->with($this->routeMock)->will($this->returnValue(true)); $this->dmMock->expects($this->once())->method('getLocalesFor')->with($this->routeMock, true)->will($this->returnValue(array('en', 'de', 'fr'))); $this->routeMock->expects($this->once())->method('setRequirement')->with('_locale', 'en|de|fr'); $this->listener->setUpdateAvailableTranslations(true); $args = new LifecycleEventArgs($this->routeMock, $this->dmMock); $this->listener->postLoad($args); }
public function testRootEdgeCase() { $this->buildMocks('/'); $this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(get_class($this->object))->will($this->returnValue($this->documentManager)); $this->documentManager->expects($this->any())->method('getNodeForDocument')->with($this->object)->willReturn($this->node); $this->node->expects($this->any())->method('getDepth')->will($this->returnValue(4)); $urlInformation = new UrlInformation(); $this->guesser->guessValues($urlInformation, $this->object, 'default'); $this->assertEquals(3, $urlInformation->getDepth()); }
/** * @dataProvider provideExpandClassName */ public function testExpandClassName($className, $fqClassName, $isAlias) { if ($isAlias) { $this->dm->expects($this->once())->method('getClassMetadata')->with($className)->will($this->returnValue($this->metadata)); $this->metadata->expects($this->once())->method('getName')->will($this->returnValue($fqClassName)); } $refl = new \ReflectionClass($this->mapper); $method = $refl->getMethod('expandClassName'); $method->setAccessible(true); $res = $method->invoke($this->mapper, $this->dm, $className); $this->assertEquals($fqClassName, $res); }
/** * Use getRouteByName() with two different document managers. * The two document managers will return different route objects when searching for the same path. */ public function testChangingDocumentManager() { $this->routeMock->expects($this->any())->method('getPath')->will($this->returnValue('/cms/routes/test-route')); $this->route2Mock->expects($this->any())->method('getPath')->will($this->returnValue('/cms/routes/new-route')); $this->dmMock->expects($this->any())->method('find')->with(null, '/cms/routes/test-route')->will($this->returnValue($this->routeMock)); $this->dm2Mock->expects($this->any())->method('find')->with(null, '/cms/routes/test-route')->will($this->returnValue($this->route2Mock)); $objectManagers = array('default' => $this->dmMock, 'new_manager' => $this->dm2Mock); $this->managerRegistryMock = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->managerRegistryMock->expects($this->any())->method('getManager')->will($this->returnCallback(function ($name) use($objectManagers) { return $objectManagers[$name]; })); $this->candidatesMock->expects($this->any())->method('isCandidate')->will($this->returnValue(true)); $routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock); $routeProvider->setManagerName('default'); $foundRoute = $routeProvider->getRouteByName('/cms/routes/test-route'); $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $foundRoute); $this->assertEquals('/cms/routes/test-route', $foundRoute->getPath()); $routeProvider->setManagerName('new_manager'); $newFoundRoute = $routeProvider->getRouteByName('/cms/routes/test-route'); $this->assertInstanceOf('Symfony\\Component\\Routing\\Route', $newFoundRoute); $this->assertEquals('/cms/routes/new-route', $newFoundRoute->getPath()); }