public function __clone() { $resources = new ArrayCollection(); if ($this->resources) { foreach ($this->resources as $r) { $resources->add($r); } } $this->resources = $resources; }
public function __invoke(JobEvent $event) { $job = $event->getJobEntity(); $invoiceAddressDraft = $this->draftRepository->findByJobId($job->getId()); $invoiceAddress = $invoiceAddressDraft->getInvoiceAddress(); $snapshotBuilder = new Builder(); $snapshot = $snapshotBuilder->build($job); $products = new ArrayCollection(); foreach ($job->getPortals() as $key) { $product = new Product(); $channel = $this->providerOptions->getChannel($key); $product->setName($channel->getLabel())->setProductNumber($channel->getExternalKey())->setQuantity(1); $products->add($product); } $data = ['type' => OrderInterface::TYPE_JOB, 'taxRate' => $this->options->getTaxRate(), 'price' => $this->priceFilter->filter($job->getPortals()), 'invoiceAddress' => $invoiceAddress, 'currency' => $this->options->getCurrency(), 'currencySymbol' => $this->options->getCurrencySymbol(), 'entity' => $snapshot, 'products' => $products]; $order = $this->orderRepository->create($data); $this->orderRepository->store($order); $this->draftRepository->remove($invoiceAddressDraft); }
public function testUpdatesFilesPermissionsOnFlush() { /* * Prepare */ $permissions = $this->getMockBuilder(Permissions::class)->setMethods(['hasChanged'])->getMock(); $permissions->expects($this->exactly(2))->method('hasChanged')->willReturn(true); $document = new Ufps_TargetDocument(); $document->setPermissions($permissions); $filePermissions = $this->getMockBuilder(Permissions::class)->setMethods(['clear', 'inherit'])->getMock(); $file = new FileEntity(); $file->setPermissions($filePermissions); $collection = new ArrayCollection(); $collection->add($file); $document->singleFile = $file; $document->fileCollection = $collection; $inserts = [$document]; $updates = [$document]; $filePermissions->expects($this->exactly(4))->method('clear')->will($this->returnSelf()); $filePermissions->expects($this->exactly(4))->method('inherit')->with($permissions)->will($this->returnSelf()); $dm = $this->getMockBuilder(DocumentManager::class)->setMethods(['getUnitOfWork', 'getClassMetadata', 'persist'])->disableOriginalConstructor()->getMock(); $uow = $this->getMockBuilder(UnitOfWork::class)->setMethods(['computeChangeSet', 'getScheduledDocumentInsertions', 'getScheduledDocumentUpdates'])->disableOriginalConstructor()->getMock(); $args = $this->getMockBuilder(OnFlushEventArgs::class)->setMethods(['getDocumentManager'])->disableOriginalConstructor()->getMock(); $args->expects($this->once())->method('getDocumentManager')->willReturn($dm); $metaData = $this->getMockBuilder('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $dm->expects($this->once())->method('getUnitOfWork')->willReturn($uow); $dm->expects($this->exactly(4))->method('getClassMetaData')->with(FileEntity::class)->willReturn($metaData); $dm->expects($this->exactly(2))->method('persist')->with($this->identicalTo($filePermissions)); $uow->expects($this->once())->method('getScheduledDocumentInsertions')->willReturn($inserts); $uow->expects($this->once())->method('getScheduledDocumentUpdates')->willReturn($updates); $uow->expects($this->exactly(4))->method('computeChangeSet')->with($metaData, $file); /* * Execute */ $this->target->onFlush($args); }
/** * @testdox createService() returns select element with value options if organization is associated to the user. */ public function testCreateServiceWithAssociation() { /* @var $org \PHPUnit_Framework_MockObject_MockObject */ $org = $this->user->getOrganization(); $org->expects($this->once())->method('hasAssociation')->willReturn(true); $orgs = new ArrayCollection(); $org0 = $this->generateOrganizationEntity('testOrg0', 'testOrg0.name', 'org0.testCity', 'org0.testStreet', 'org0.1234'); $org1 = $this->generateOrganizationEntity('testOrg1', 'testOrg1.name', 'org1.city', 'org1.street', 'org1.number'); $orgs->add($org1); $org->expects($this->once())->method('getHiringOrganizations')->willReturn($orgs); $org->expects($this->once())->method('getOrganization')->willReturn($org0); $expect = array('testOrg0' => 'testOrg0.name|org0.testCity|org0.testStreet|org0.1234|', 'testOrg1' => 'testOrg1.name|org1.city|org1.street|org1.number|'); $select = $this->target->createService($this->formElements); $actual = $select->getValueOptions(); $this->assertEquals($expect, $actual); }
/** * @testdox Allows setting/getting multi job applications * @covers Jobs\Entity\Job::getApplications * @covers Jobs\Entity\Job::setApplications */ public function testSetGetApplications() { $arrayCollection = new ArrayCollection(); $application = new Application(); $application->setIsDraft(false); $application->setId(123); $arrayCollection->add($application); $this->target->setApplications($arrayCollection); $this->assertEquals($arrayCollection, $this->target->getApplications()); }
/** * Creates a collection of normalized embedded documents. * * @param string $type * @uses getHydrator(), getEntity(), getData() * @return \Core\Entity\Collection\ArrayCollection */ protected function getCollection($type) { $collection = new ArrayCollection(); $key = $this->config[$type]['key']; $hydrator = $this->getHydrator($type); $filter = 'filter' . rtrim($type, 's'); $entity = $this->getEntity($type); $dataArray = $this->getData($key); if ($dataArray) { foreach ($dataArray as $data) { $data = $this->{$filter}($data); if (!count($data)) { continue; } $current = $hydrator->hydrate($data, clone $entity); $collection->add($current); } } return $collection; }
/** * Gets an Assertion event seeded with Mock objects. * * @param bool $isOneEmployeeAllowed if true, one employee in the employees collection gets job create permissions. * * @return AssertionEvent */ protected function getTestEvent($isOneEmployeeAllowed = true) { $employees = new ArrayCollection(); for ($i = 0; $i < 3; $i++) { $empUser = new User(); $empUser->setId('1234-' . $i); $perm = new EmployeePermissions(EmployeePermissionsInterface::JOBS_VIEW); if (2 == $i && $isOneEmployeeAllowed) { $perm->grant(EmployeePermissionsInterface::JOBS_CREATE); } $emp = new Employee($empUser, $perm); $employees->add($emp); } $org = $this->getMockBuilder('\\Organizations\\Entity\\OrganizationReference')->disableOriginalConstructor()->getMock(); $org->expects($this->once())->method('hasAssociation')->willReturn(true); $org->expects($this->once())->method('isOwner')->willReturn(false); $org->expects($this->once())->method('getEmployees')->willReturn($employees); $role = new User(); $role->setId('1234-2'); $role->setOrganization($org); $e = new AssertionEvent(); $e->setRole($role); return $e; }
/** * Gets a list of Employees by a user role * * @param string $role * * @return ArrayCollection */ public function getEmployeesByRole($role) { $employees = new ArrayCollection(); /* @var \Organizations\Entity\Employee $employee */ foreach ($this->getEmployees() as $employee) { if ($role === $employee->getRole()) { $employees->add($employee); } } return $employees; }
/** * @covers Applications\Entity\Application::getHistory * @covers Applications\Entity\Application::setHistory */ public function testSetGetHistory() { $history = new History(Status::INCOMING, 'MESSAGE'); $array = new ArrayCollection(); $array->add($history); $this->target->setHistory($array); $this->assertEquals($array, $this->target->getHistory()); }