Skip to content

Commit a5dbd62

Browse files
committed
fixing all command tests
1 parent 676e594 commit a5dbd62

6 files changed

Lines changed: 48 additions & 101 deletions

Tests/Command/ActivateUserCommandTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace FOS\UserBundle\Tests\Command;
1313

1414
use FOS\UserBundle\Command\ActivateUserCommand;
15+
use FOS\UserBundle\Util\UserManipulator;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1919

2020
class ActivateUserCommandTest extends TestCase
2121
{
2222
public function testExecute()
2323
{
24-
$commandTester = $this->createCommandTester($this->getContainer('user'));
24+
$commandTester = $this->createCommandTester($this->getManipulator('user'));
2525
$exitCode = $commandTester->execute(array(
2626
'username' => 'user',
2727
), array(
@@ -47,7 +47,7 @@ public function testExecuteInteractiveWithQuestionHelper()
4747

4848
$application->getHelperSet()->set($helper, 'question');
4949

50-
$commandTester = $this->createCommandTester($this->getContainer('user'), $application);
50+
$commandTester = $this->createCommandTester($this->getManipulator('user'), $application);
5151
$exitCode = $commandTester->execute(array(), array(
5252
'decorated' => false,
5353
'interactive' => true,
@@ -58,21 +58,20 @@ public function testExecuteInteractiveWithQuestionHelper()
5858
}
5959

6060
/**
61-
* @param ContainerInterface $container
61+
* @param UserManipulator $manipulator
6262
* @param Application|null $application
6363
*
6464
* @return CommandTester
6565
*/
66-
private function createCommandTester(ContainerInterface $container, Application $application = null)
66+
private function createCommandTester(UserManipulator $manipulator, Application $application = null)
6767
{
6868
if (null === $application) {
6969
$application = new Application();
7070
}
7171

7272
$application->setAutoExit(false);
7373

74-
$command = new ActivateUserCommand();
75-
$command->setContainer($container);
74+
$command = new ActivateUserCommand($manipulator);
7675

7776
$application->add($command);
7877

@@ -84,10 +83,8 @@ private function createCommandTester(ContainerInterface $container, Application
8483
*
8584
* @return mixed
8685
*/
87-
private function getContainer($username)
86+
private function getManipulator($username)
8887
{
89-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
90-
9188
$manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator')
9289
->disableOriginalConstructor()
9390
->getMock();
@@ -98,12 +95,6 @@ private function getContainer($username)
9895
->with($username)
9996
;
10097

101-
$container
102-
->expects($this->once())
103-
->method('get')
104-
->with('fos_user.util.user_manipulator')
105-
->will($this->returnValue($manipulator));
106-
107-
return $container;
98+
return $manipulator;
10899
}
109100
}

Tests/Command/ChangePasswordCommandTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace FOS\UserBundle\Tests\Command;
1313

1414
use FOS\UserBundle\Command\ChangePasswordCommand;
15+
use FOS\UserBundle\Util\UserManipulator;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1919

2020
class ChangePasswordCommandTest extends TestCase
2121
{
2222
public function testExecute()
2323
{
24-
$commandTester = $this->createCommandTester($this->getContainer('user', 'pass'));
24+
$commandTester = $this->createCommandTester($this->getManipulator('user', 'pass'));
2525
$exitCode = $commandTester->execute(array(
2626
'username' => 'user',
2727
'password' => 'pass',
@@ -51,7 +51,7 @@ public function testExecuteInteractiveWithQuestionHelper()
5151

5252
$application->getHelperSet()->set($helper, 'question');
5353

54-
$commandTester = $this->createCommandTester($this->getContainer('user', 'pass'), $application);
54+
$commandTester = $this->createCommandTester($this->getManipulator('user', 'pass'), $application);
5555
$exitCode = $commandTester->execute(array(), array(
5656
'decorated' => false,
5757
'interactive' => true,
@@ -62,21 +62,20 @@ public function testExecuteInteractiveWithQuestionHelper()
6262
}
6363

6464
/**
65-
* @param ContainerInterface $container
65+
* @param UserManipulator $container
6666
* @param Application|null $application
6767
*
6868
* @return CommandTester
6969
*/
70-
private function createCommandTester(ContainerInterface $container, Application $application = null)
70+
private function createCommandTester(UserManipulator $userManipulator, Application $application = null)
7171
{
7272
if (null === $application) {
7373
$application = new Application();
7474
}
7575

7676
$application->setAutoExit(false);
7777

78-
$command = new ChangePasswordCommand();
79-
$command->setContainer($container);
78+
$command = new ChangePasswordCommand($userManipulator);
8079

8180
$application->add($command);
8281

@@ -89,10 +88,8 @@ private function createCommandTester(ContainerInterface $container, Application
8988
*
9089
* @return mixed
9190
*/
92-
private function getContainer($username, $password)
91+
private function getManipulator($username, $password)
9392
{
94-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
95-
9693
$manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator')
9794
->disableOriginalConstructor()
9895
->getMock();
@@ -103,12 +100,6 @@ private function getContainer($username, $password)
103100
->with($username, $password)
104101
;
105102

106-
$container
107-
->expects($this->once())
108-
->method('get')
109-
->with('fos_user.util.user_manipulator')
110-
->will($this->returnValue($manipulator));
111-
112-
return $container;
103+
return $manipulator;
113104
}
114105
}

Tests/Command/CreateUserCommandTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace FOS\UserBundle\Tests\Command;
1313

1414
use FOS\UserBundle\Command\CreateUserCommand;
15+
use FOS\UserBundle\Util\UserManipulator;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1919

2020
class CreateUserCommandTest extends TestCase
2121
{
2222
public function testExecute()
2323
{
24-
$commandTester = $this->createCommandTester($this->getContainer('user', 'pass', 'email', true, false));
24+
$commandTester = $this->createCommandTester($this->getManipulator('user', 'pass', 'email', true, false));
2525
$exitCode = $commandTester->execute(array(
2626
'username' => 'user',
2727
'email' => 'email',
@@ -58,7 +58,7 @@ public function testExecuteInteractiveWithQuestionHelper()
5858
$application->getHelperSet()->set($helper, 'question');
5959

6060
$commandTester = $this->createCommandTester(
61-
$this->getContainer('user', 'pass', 'email', true, false), $application
61+
$this->getManipulator('user', 'pass', 'email', true, false), $application
6262
);
6363
$exitCode = $commandTester->execute(array(), array(
6464
'decorated' => false,
@@ -70,21 +70,20 @@ public function testExecuteInteractiveWithQuestionHelper()
7070
}
7171

7272
/**
73-
* @param ContainerInterface $container
73+
* @param UserManipulator $manipulator
7474
* @param Application|null $application
7575
*
7676
* @return CommandTester
7777
*/
78-
private function createCommandTester(ContainerInterface $container, Application $application = null)
78+
private function createCommandTester(UserManipulator $manipulator, Application $application = null)
7979
{
8080
if (null === $application) {
8181
$application = new Application();
8282
}
8383

8484
$application->setAutoExit(false);
8585

86-
$command = new CreateUserCommand();
87-
$command->setContainer($container);
86+
$command = new CreateUserCommand($manipulator);
8887

8988
$application->add($command);
9089

@@ -100,10 +99,8 @@ private function createCommandTester(ContainerInterface $container, Application
10099
*
101100
* @return mixed
102101
*/
103-
private function getContainer($username, $password, $email, $active, $superadmin)
102+
private function getManipulator($username, $password, $email, $active, $superadmin)
104103
{
105-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
106-
107104
$manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator')
108105
->disableOriginalConstructor()
109106
->getMock();
@@ -114,12 +111,6 @@ private function getContainer($username, $password, $email, $active, $superadmin
114111
->with($username, $password, $email, $active, $superadmin)
115112
;
116113

117-
$container
118-
->expects($this->once())
119-
->method('get')
120-
->with('fos_user.util.user_manipulator')
121-
->will($this->returnValue($manipulator));
122-
123-
return $container;
114+
return $manipulator;
124115
}
125116
}

Tests/Command/DeactivateUserCommandTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace FOS\UserBundle\Tests\Command;
1313

1414
use FOS\UserBundle\Command\DeactivateUserCommand;
15+
use FOS\UserBundle\Util\UserManipulator;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1919

2020
class DeactivateUserCommandTest extends TestCase
2121
{
2222
public function testExecute()
2323
{
24-
$commandTester = $this->createCommandTester($this->getContainer('user'));
24+
$commandTester = $this->createCommandTester($this->getManipulator('user'));
2525
$exitCode = $commandTester->execute(array(
2626
'username' => 'user',
2727
), array(
@@ -47,7 +47,7 @@ public function testExecuteInteractiveWithQuestionHelper()
4747

4848
$application->getHelperSet()->set($helper, 'question');
4949

50-
$commandTester = $this->createCommandTester($this->getContainer('user'), $application);
50+
$commandTester = $this->createCommandTester($this->getManipulator('user'), $application);
5151
$exitCode = $commandTester->execute(array(), array(
5252
'decorated' => false,
5353
'interactive' => true,
@@ -58,21 +58,20 @@ public function testExecuteInteractiveWithQuestionHelper()
5858
}
5959

6060
/**
61-
* @param ContainerInterface $container
61+
* @param UserManipulator $manipulator
6262
* @param Application|null $application
6363
*
6464
* @return CommandTester
6565
*/
66-
private function createCommandTester(ContainerInterface $container, Application $application = null)
66+
private function createCommandTester(UserManipulator $manipulator, Application $application = null)
6767
{
6868
if (null === $application) {
6969
$application = new Application();
7070
}
7171

7272
$application->setAutoExit(false);
7373

74-
$command = new DeactivateUserCommand();
75-
$command->setContainer($container);
74+
$command = new DeactivateUserCommand($manipulator);
7675

7776
$application->add($command);
7877

@@ -84,10 +83,8 @@ private function createCommandTester(ContainerInterface $container, Application
8483
*
8584
* @return mixed
8685
*/
87-
private function getContainer($username)
86+
private function getManipulator($username)
8887
{
89-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
90-
9188
$manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator')
9289
->disableOriginalConstructor()
9390
->getMock();
@@ -98,12 +95,6 @@ private function getContainer($username)
9895
->with($username)
9996
;
10097

101-
$container
102-
->expects($this->once())
103-
->method('get')
104-
->with('fos_user.util.user_manipulator')
105-
->will($this->returnValue($manipulator));
106-
107-
return $container;
98+
return $manipulator;
10899
}
109100
}

Tests/Command/DemoteUserCommandTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
namespace FOS\UserBundle\Tests\Command;
1313

1414
use FOS\UserBundle\Command\DemoteUserCommand;
15+
use FOS\UserBundle\Util\UserManipulator;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Component\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1919

2020
class DemoteUserCommandTest extends TestCase
2121
{
2222
public function testExecute()
2323
{
24-
$commandTester = $this->createCommandTester($this->getContainer('user', 'role', false));
24+
$commandTester = $this->createCommandTester($this->getManipulator('user', 'role', false));
2525
$exitCode = $commandTester->execute(array(
2626
'username' => 'user',
2727
'role' => 'role',
@@ -51,7 +51,7 @@ public function testExecuteInteractiveWithQuestionHelper()
5151

5252
$application->getHelperSet()->set($helper, 'question');
5353

54-
$commandTester = $this->createCommandTester($this->getContainer('user', 'role', false), $application);
54+
$commandTester = $this->createCommandTester($this->getManipulator('user', 'role', false), $application);
5555
$exitCode = $commandTester->execute(array(), array(
5656
'decorated' => false,
5757
'interactive' => true,
@@ -62,21 +62,20 @@ public function testExecuteInteractiveWithQuestionHelper()
6262
}
6363

6464
/**
65-
* @param ContainerInterface $container
65+
* @param UserManipulator $manipulator
6666
* @param Application|null $application
6767
*
6868
* @return CommandTester
6969
*/
70-
private function createCommandTester(ContainerInterface $container, Application $application = null)
70+
private function createCommandTester(UserManipulator $manipulator, Application $application = null)
7171
{
7272
if (null === $application) {
7373
$application = new Application();
7474
}
7575

7676
$application->setAutoExit(false);
7777

78-
$command = new DemoteUserCommand();
79-
$command->setContainer($container);
78+
$command = new DemoteUserCommand($manipulator);
8079

8180
$application->add($command);
8281

@@ -90,10 +89,8 @@ private function createCommandTester(ContainerInterface $container, Application
9089
*
9190
* @return mixed
9291
*/
93-
private function getContainer($username, $role, $super)
92+
private function getManipulator($username, $role, $super)
9493
{
95-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
96-
9794
$manipulator = $this->getMockBuilder('FOS\UserBundle\Util\UserManipulator')
9895
->disableOriginalConstructor()
9996
->getMock();
@@ -114,12 +111,6 @@ private function getContainer($username, $role, $super)
114111
;
115112
}
116113

117-
$container
118-
->expects($this->once())
119-
->method('get')
120-
->with('fos_user.util.user_manipulator')
121-
->will($this->returnValue($manipulator));
122-
123-
return $container;
114+
return $manipulator;
124115
}
125116
}

0 commit comments

Comments
 (0)