Skip to content

Commit

Permalink
imvprove create tenant command
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Mar 6, 2017
1 parent b5055ad commit 7b6110c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions Command/CreateTenantCommand.php
Expand Up @@ -73,6 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($default) {
$name = TenantInterface::DEFAULT_TENANT_NAME;
$domain = $this->getContainer()->getParameter('domain');
$organization = $this->getOrganizationRepository()->findOneByName(OrganizationInterface::DEFAULT_NAME);
if (null === $organization) {
throw new \InvalidArgumentException('Default organization doesn\'t exist!');
Expand Down
15 changes: 12 additions & 3 deletions Tests/Command/CreateTenantCommandTest.php
Expand Up @@ -49,7 +49,7 @@ public function testExecuteWhenCreatingNewTenant()
$this->question->setInputStream($this->getInputStream("domain.dev\nTest\n123456\n"));
$tenant = new Tenant();
$tenant->setCode('123abc');
$this->command->setContainer($this->getMockContainer(null, new Organization(), $tenant, 'subdomain'));
$this->command->setContainer($this->getMockContainer(null, new Organization(), $tenant, 'subdomain', 'domain.dev'));
$this->commandTester = new CommandTester($this->command);
$this->commandTester->execute(['command' => $this->command->getName()]);

Expand Down Expand Up @@ -123,7 +123,7 @@ public function testExecuteDisabledTenant()
$this->question->setInputStream($this->getInputStream("example.com\nExample\n123456\n"));
$tenant = new Tenant();
$tenant->setCode('123abc');
$this->command->setContainer($this->getMockContainer(null, new Organization(), $tenant, 'example'));
$this->command->setContainer($this->getMockContainer(null, new Organization(), $tenant, 'example', 'example.com'));
$this->commandTester = new CommandTester($this->command);
$this->commandTester->execute([
'command' => $this->command->getName(),
Expand Down Expand Up @@ -159,6 +159,11 @@ private function getMockContainer($mockTenant = null, $mockOrganization = null,
->with($subdomain, $domain)
->willReturn($mockTenant);

$mockRepo->expects($this->any())
->method('findOneByDomain')
->with($domain)
->willReturn($mockTenant);

$mockDoctrine = $this
->getMockBuilder('Doctrine\ORM\EntityManager')
->disableOriginalConstructor()
Expand All @@ -183,13 +188,17 @@ private function getMockContainer($mockTenant = null, $mockOrganization = null,

$mockContainer->expects($this->any())
->method('get')
->will($this->returnValueMap([
->will(self::returnValueMap([
['swp.object_manager.tenant', 1, $mockDoctrine],
['swp.repository.tenant', 1, $mockRepo],
['swp.repository.organization', 1, $mockRepoOrganization],
['swp.factory.tenant', 1, $mockFactory],
]));

$mockContainer->expects($this->any())
->method('getParameter')
->willReturn('localhost');

return $mockContainer;
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": "^7.0",
"symfony/framework-bundle": "~2.6|~3.0",
"swp/multi-tenancy": "~0.1.0",
"swp/multi-tenancy": ">=v0.5.1",
"doctrine/doctrine-bundle": "~1.3",
"twig/twig": "^1.24.0",
"swp/storage-bundle": "~0.1.0",
Expand All @@ -25,7 +25,7 @@
"symfony/dependency-injection": "^2.6"
},
"require-dev": {
"phpunit/phpunit": "5.*",
"phpunit/phpunit": "^5.3",
"phpspec/phpspec": "^3.0",
"symfony/expression-language": "~2.6|~3.0",
"symfony-cmf/routing-bundle": "^1.3",
Expand Down

0 comments on commit 7b6110c

Please sign in to comment.