Completed
Push — master ( dcdc51...16ea71 )
by Aimeos
03:11
created
Tests/Command/AccountCommandTest.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 		$kernel = $this->createKernel();
17 17
 		$kernel->boot();
18 18
 
19
-		$application = new Application( $kernel );
20
-		$application->add( new Command\AccountCommand() );
19
+		$application = new Application($kernel);
20
+		$application->add(new Command\AccountCommand());
21 21
 
22
-		$command = $application->find( 'aimeos:account' );
23
-		$commandTester = new CommandTester( $command );
24
-		$commandTester->execute( array( 'command' => $command->getName(), 'site' => 'unittest', 'email' => '[email protected]', '--password' => 'test' ) );
22
+		$command = $application->find('aimeos:account');
23
+		$commandTester = new CommandTester($command);
24
+		$commandTester->execute(array('command' => $command->getName(), 'site' => 'unittest', 'email' => '[email protected]', '--password' => 'test'));
25 25
 
26
-		$this->assertEquals( 0, $commandTester->getStatusCode() );
26
+		$this->assertEquals(0, $commandTester->getStatusCode());
27 27
 	}
28 28
 
29 29
 
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
 		$kernel = $this->createKernel();
33 33
 		$kernel->boot();
34 34
 
35
-		$application = new Application( $kernel );
36
-		$application->add( new Command\AccountCommand() );
35
+		$application = new Application($kernel);
36
+		$application->add(new Command\AccountCommand());
37 37
 
38
-		$command = $application->find( 'aimeos:account' );
39
-		$commandTester = new CommandTester( $command );
40
-		$commandTester->execute( array( 'command' => $command->getName(), 'site' => 'unittest', 'email' => '[email protected]', '--password' => 'test', '--admin' => true ) );
38
+		$command = $application->find('aimeos:account');
39
+		$commandTester = new CommandTester($command);
40
+		$commandTester->execute(array('command' => $command->getName(), 'site' => 'unittest', 'email' => '[email protected]', '--password' => 'test', '--admin' => true));
41 41
 
42
-		$this->assertEquals( 0, $commandTester->getStatusCode() );
42
+		$this->assertEquals(0, $commandTester->getStatusCode());
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
Command/AccountCommand.php 2 patches
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	protected function configure()
31 31
 	{
32
-		$this->setName( 'aimeos:account');
33
-		$this->setDescription( 'Creates new (admin) accounts' );
34
-		$this->addArgument( 'email', InputArgument::REQUIRED, 'E-mail address of the account that should be created' );
35
-		$this->addArgument( 'site', InputArgument::OPTIONAL, 'Site codes to create accounts for like "default unittest" (none for all)' );
36
-		$this->addOption( 'password', null, InputOption::VALUE_REQUIRED, 'Optional password for the account (will ask for if not given)' );
37
-		$this->addOption( 'admin', null, InputOption::VALUE_NONE, 'If account should have administrator privileges' );
38
-		$this->addOption( 'editor', null, InputOption::VALUE_NONE, 'If account should have limited editor privileges' );
32
+		$this->setName('aimeos:account');
33
+		$this->setDescription('Creates new (admin) accounts');
34
+		$this->addArgument('email', InputArgument::REQUIRED, 'E-mail address of the account that should be created');
35
+		$this->addArgument('site', InputArgument::OPTIONAL, 'Site codes to create accounts for like "default unittest" (none for all)');
36
+		$this->addOption('password', null, InputOption::VALUE_REQUIRED, 'Optional password for the account (will ask for if not given)');
37
+		$this->addOption('admin', null, InputOption::VALUE_NONE, 'If account should have administrator privileges');
38
+		$this->addOption('editor', null, InputOption::VALUE_NONE, 'If account should have limited editor privileges');
39 39
 	}
40 40
 
41 41
 
@@ -45,32 +45,32 @@  discard block
 block discarded – undo
45 45
 	 * @param InputInterface $input Input object
46 46
 	 * @param OutputInterface $output Output object
47 47
 	 */
48
-	protected function execute( InputInterface $input, OutputInterface $output )
48
+	protected function execute(InputInterface $input, OutputInterface $output)
49 49
 	{
50
-		$code = $input->getArgument( 'email' );
51
-		if( ( $password = $input->getOption( 'password' ) ) === null )
50
+		$code = $input->getArgument('email');
51
+		if (($password = $input->getOption('password')) === null)
52 52
 		{
53
-			$helper = $this->getHelper( 'question' );
54
-			$question = new Question( 'Password' );
55
-			$question->setHidden( true );
53
+			$helper = $this->getHelper('question');
54
+			$question = new Question('Password');
55
+			$question->setHidden(true);
56 56
 
57
-			$password = $helper->ask( $input, $output, $question );
57
+			$password = $helper->ask($input, $output, $question);
58 58
 		}
59 59
 
60
-		$context = $this->getContainer()->get( 'aimeos_context' )->get( false );
61
-		$context->setEditor( 'aimeos:account' );
60
+		$context = $this->getContainer()->get('aimeos_context')->get(false);
61
+		$context->setEditor('aimeos:account');
62 62
 
63
-		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context );
64
-		$context->setLocale( $localeManager->createItem() );
63
+		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($context);
64
+		$context->setLocale($localeManager->createItem());
65 65
 
66
-		$user = $this->createCustomerItem( $context, $code, $password );
66
+		$user = $this->createCustomerItem($context, $code, $password);
67 67
 
68
-		if( $input->getOption( 'admin' ) ) {
69
-			$this->addGroup( $input, $context, $user, 'admin' );
68
+		if ($input->getOption('admin')) {
69
+			$this->addGroup($input, $context, $user, 'admin');
70 70
 		}
71 71
 
72
-		if( $input->getOption( 'editor' ) ) {
73
-			$this->addGroup( $input, $context, $user, 'editor' );
72
+		if ($input->getOption('editor')) {
73
+			$this->addGroup($input, $context, $user, 'editor');
74 74
 		}
75 75
 	}
76 76
 
@@ -83,24 +83,24 @@  discard block
 block discarded – undo
83 83
 	 * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object
84 84
 	 * @param string $group Unique customer group code
85 85
 	 */
86
-	protected function addGroup( InputInterface $input, \Aimeos\MShop\Context\Item\Iface $context,
87
-		\Aimeos\MShop\Customer\Item\Iface $user, $group )
86
+	protected function addGroup(InputInterface $input, \Aimeos\MShop\Context\Item\Iface $context,
87
+		\Aimeos\MShop\Customer\Item\Iface $user, $group)
88 88
 	{
89
-		$output->writeln( sprintf( 'Add "%1$s" group to user "%2$s" for sites', $group, $user->getCode() ) );
89
+		$output->writeln(sprintf('Add "%1$s" group to user "%2$s" for sites', $group, $user->getCode()));
90 90
 
91
-		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context );
91
+		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($context);
92 92
 
93
-		foreach( $this->getSiteItems( $context, $input ) as $siteItem )
93
+		foreach ($this->getSiteItems($context, $input) as $siteItem)
94 94
 		{
95
-			$localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false );
95
+			$localeItem = $localeManager->bootstrap($siteItem->getCode(), '', '', false);
96 96
 
97 97
 			$lcontext = clone $context;
98
-			$lcontext->setLocale( $localeItem );
98
+			$lcontext->setLocale($localeItem);
99 99
 
100
-			$output->writeln( '- ' . $siteItem->getCode() );
100
+			$output->writeln('- '.$siteItem->getCode());
101 101
 
102
-			$groupItem = $this->getGroupItem( $lcontext, $group );
103
-			$this->addListItem( $lcontext, $user->getId(), $groupItem->getId() );
102
+			$groupItem = $this->getGroupItem($lcontext, $group);
103
+			$this->addListItem($lcontext, $user->getId(), $groupItem->getId());
104 104
 		}
105 105
 	}
106 106
 
@@ -112,31 +112,31 @@  discard block
 block discarded – undo
112 112
 	 * @param string $userid Unique user ID
113 113
 	 * @param string $groupid Unique group ID
114 114
 	 */
115
-	protected function addListItem( \Aimeos\MShop\Context\Item\Iface $context, $userid, $groupid )
115
+	protected function addListItem(\Aimeos\MShop\Context\Item\Iface $context, $userid, $groupid)
116 116
 	{
117
-		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $context )->getSubmanager( 'lists' );
118
-		$typeid = $manager->getSubmanager( 'type' )->findItem( 'default', array(), 'customer/group' )->getId();
117
+		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager($context)->getSubmanager('lists');
118
+		$typeid = $manager->getSubmanager('type')->findItem('default', array(), 'customer/group')->getId();
119 119
 
120 120
 		$search = $manager->createSearch();
121 121
 		$expr = array(
122
-			$search->compare( '==', 'customer.lists.parentid', $userid ),
123
-			$search->compare( '==', 'customer.lists.refid', $groupid ),
124
-			$search->compare( '==', 'customer.lists.domain', 'customer/group' ),
125
-			$search->compare( '==', 'customer.lists.typeid', $typeid ),
122
+			$search->compare('==', 'customer.lists.parentid', $userid),
123
+			$search->compare('==', 'customer.lists.refid', $groupid),
124
+			$search->compare('==', 'customer.lists.domain', 'customer/group'),
125
+			$search->compare('==', 'customer.lists.typeid', $typeid),
126 126
 		);
127
-		$search->setConditions( $search->combine( '&&', $expr ) );
128
-		$search->setSlice( 0, 1 );
127
+		$search->setConditions($search->combine('&&', $expr));
128
+		$search->setSlice(0, 1);
129 129
 
130
-		if( count( $manager->searchItems( $search ) ) === 0 )
130
+		if (count($manager->searchItems($search)) === 0)
131 131
 		{
132 132
 			$item = $manager->createItem();
133
-			$item->setDomain( 'customer/group' );
134
-			$item->setParentId( $userid );
135
-			$item->setTypeId( $typeid );
136
-			$item->setRefId( $groupid );
137
-			$item->setStatus( 1 );
133
+			$item->setDomain('customer/group');
134
+			$item->setParentId($userid);
135
+			$item->setTypeId($typeid);
136
+			$item->setRefId($groupid);
137
+			$item->setStatus(1);
138 138
 
139
-			$manager->saveItem( $item, false );
139
+			$manager->saveItem($item, false);
140 140
 		}
141 141
 	}
142 142
 
@@ -151,22 +151,22 @@  discard block
 block discarded – undo
151 151
 	 * @param string $password New user password
152 152
 	 * @return \Aimeos\MShop\Customer\Item\Iface Aimeos customer item object
153 153
 	 */
154
-	protected function createCustomerItem( \Aimeos\MShop\Context\Item\Iface $context, $email, $password )
154
+	protected function createCustomerItem(\Aimeos\MShop\Context\Item\Iface $context, $email, $password)
155 155
 	{
156
-		$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' );
156
+		$manager = \Aimeos\MShop\Factory::createManager($context, 'customer');
157 157
 
158 158
 		try {
159
-			$item = $manager->findItem( $email );
160
-		} catch( \Aimeos\MShop\Exception $e ) {
159
+			$item = $manager->findItem($email);
160
+		} catch (\Aimeos\MShop\Exception $e) {
161 161
 			$item = $manager->createItem();
162 162
 		}
163 163
 
164
-		$item->setCode( $email );
165
-		$item->setLabel( $email );
166
-		$item->getPaymentAddress()->setEmail( $email );
167
-		$item->setPassword( $password );
164
+		$item->setCode($email);
165
+		$item->setLabel($email);
166
+		$item->getPaymentAddress()->setEmail($email);
167
+		$item->setPassword($password);
168 168
 
169
-		$manager->saveItem( $item );
169
+		$manager->saveItem($item);
170 170
 
171 171
 		return $item;
172 172
 	}
@@ -179,21 +179,21 @@  discard block
 block discarded – undo
179 179
 	 * @param string $code Unique customer group code
180 180
 	 * @return \Aimeos\MShop\Customer\Item\Group\Iface Aimeos customer group item object
181 181
 	 */
182
-	protected function getGroupItem( \Aimeos\MShop\Context\Item\Iface $context, $code )
182
+	protected function getGroupItem(\Aimeos\MShop\Context\Item\Iface $context, $code)
183 183
 	{
184
-		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $context )->getSubmanager( 'group' );
184
+		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager($context)->getSubmanager('group');
185 185
 
186 186
 		try
187 187
 		{
188
-			$item = $manager->findItem( $code );
188
+			$item = $manager->findItem($code);
189 189
 		}
190
-		catch( \Aimeos\MShop\Exception $e )
190
+		catch (\Aimeos\MShop\Exception $e)
191 191
 		{
192 192
 			$item = $manager->createItem();
193
-			$item->setLabel( $code );
194
-			$item->setCode( $code );
193
+			$item->setLabel($code);
194
+			$item->setCode($code);
195 195
 
196
-			$manager->saveItem( $item );
196
+			$manager->saveItem($item);
197 197
 		}
198 198
 
199 199
 		return $item;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -186,8 +186,7 @@
 block discarded – undo
186 186
 		try
187 187
 		{
188 188
 			$item = $manager->findItem( $code );
189
-		}
190
-		catch( \Aimeos\MShop\Exception $e )
189
+		} catch( \Aimeos\MShop\Exception $e )
191 190
 		{
192 191
 			$item = $manager->createItem();
193 192
 			$item->setLabel( $code );
Please login to merge, or discard this patch.