Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e77ff45

Browse files
committed
minor #37592 [SCA] Minor fixes on tests (fancyweb)
This PR was merged into the 3.4 branch. Discussion ---------- [SCA] Minor fixes on tests | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - I mainly fixed misordered arguments in `assertEquals()`. Commits ------- b352ff0 [SCA] Minor fixes on tests
2 parents a397c49 + b352ff0 commit e77ff45

File tree

16 files changed

+50
-47
lines changed

16 files changed

+50
-47
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testEncodeNoPasswordNoInteraction()
5050
], ['interactive' => false]);
5151

5252
$this->assertStringContainsString('[ERROR] The password must not be empty.', $this->passwordEncoderCommandTester->getDisplay());
53-
$this->assertEquals($statusCode, 1);
53+
$this->assertEquals(1, $statusCode);
5454
}
5555

5656
public function testEncodePasswordBcrypt()

src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ public function testPreviousError()
147147

148148
$flattened = FlattenException::create($exception)->getPrevious();
149149

150-
$this->assertEquals($flattened->getMessage(), 'Parse error: Oh noes!', 'The message is copied from the original exception.');
151-
$this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
152-
$this->assertEquals($flattened->getClass(), 'Symfony\Component\Debug\Exception\FatalThrowableError', 'The class is set to the class of the original exception');
150+
$this->assertEquals('Parse error: Oh noes!', $flattened->getMessage(), 'The message is copied from the original exception.');
151+
$this->assertEquals(42, $flattened->getCode(), 'The code is copied from the original exception.');
152+
$this->assertEquals('Symfony\Component\Debug\Exception\FatalThrowableError', $flattened->getClass(), 'The class is set to the class of the original exception');
153153
}
154154

155155
/**
@@ -259,7 +259,7 @@ function () {},
259259
$this->assertSame(['float', INF], $array[$i++]);
260260

261261
// assertEquals() does not like NAN values.
262-
$this->assertEquals($array[$i][0], 'float');
262+
$this->assertEquals('float', $array[$i][0]);
263263
$this->assertNan($array[$i][1]);
264264
}
265265

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,12 +846,12 @@ public function testfindTaggedServiceIds()
846846
->addTag('bar', ['bar' => 'bar'])
847847
->addTag('foo', ['foofoo' => 'foofoo'])
848848
;
849-
$this->assertEquals($builder->findTaggedServiceIds('foo'), [
849+
$this->assertEquals([
850850
'foo' => [
851851
['foo' => 'foo'],
852852
['foofoo' => 'foofoo'],
853853
],
854-
], '->findTaggedServiceIds() returns an array of service ids and its tag attributes');
854+
], $builder->findTaggedServiceIds('foo'), '->findTaggedServiceIds() returns an array of service ids and its tag attributes');
855855
$this->assertEquals([], $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services');
856856
}
857857

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ public function testTags()
224224
$def->addTag('foo', ['foo' => 'bar']);
225225
$this->assertEquals([[], ['foo' => 'bar']], $def->getTag('foo'), '->addTag() can adds the same tag several times');
226226
$def->addTag('bar', ['bar' => 'bar']);
227-
$this->assertEquals($def->getTags(), [
227+
$this->assertEquals([
228228
'foo' => [[], ['foo' => 'bar']],
229229
'bar' => [['bar' => 'bar']],
230-
], '->getTags() returns all tags');
230+
], $def->getTags(), '->getTags() returns all tags');
231231
}
232232

233233
public function testSetArgument()

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,28 @@ public function testMultiValuedFields()
170170
');
171171

172172
$this->assertEquals(
173-
array_keys($form->all()),
174-
['foo[2]', 'foo[3]', 'bar[foo][0]', 'bar[foo][foobar]']
173+
['foo[2]', 'foo[3]', 'bar[foo][0]', 'bar[foo][foobar]'],
174+
array_keys($form->all())
175175
);
176176

177-
$this->assertEquals($form->get('foo[2]')->getValue(), 'foo');
178-
$this->assertEquals($form->get('foo[3]')->getValue(), 'foo');
179-
$this->assertEquals($form->get('bar[foo][0]')->getValue(), 'foo');
180-
$this->assertEquals($form->get('bar[foo][foobar]')->getValue(), 'foo');
177+
$this->assertEquals('foo', $form->get('foo[2]')->getValue());
178+
$this->assertEquals('foo', $form->get('foo[3]')->getValue());
179+
$this->assertEquals('foo', $form->get('bar[foo][0]')->getValue());
180+
$this->assertEquals('foo', $form->get('bar[foo][foobar]')->getValue());
181181

182182
$form['foo[2]'] = 'bar';
183183
$form['foo[3]'] = 'bar';
184184

185-
$this->assertEquals($form->get('foo[2]')->getValue(), 'bar');
186-
$this->assertEquals($form->get('foo[3]')->getValue(), 'bar');
185+
$this->assertEquals('bar', $form->get('foo[2]')->getValue());
186+
$this->assertEquals('bar', $form->get('foo[3]')->getValue());
187187

188188
$form['bar'] = ['foo' => ['0' => 'bar', 'foobar' => 'foobar']];
189189

190-
$this->assertEquals($form->get('bar[foo][0]')->getValue(), 'bar');
191-
$this->assertEquals($form->get('bar[foo][foobar]')->getValue(), 'foobar');
190+
$this->assertEquals('bar', $form->get('bar[foo][0]')->getValue());
191+
$this->assertEquals(
192+
'foobar',
193+
$form->get('bar[foo][foobar]')->getValue()
194+
);
192195
}
193196

194197
/**
@@ -967,7 +970,7 @@ public function testGetPhpValuesWithEmptyTextarea()
967970

968971
$nodes = $dom->getElementsByTagName('form');
969972
$form = new Form($nodes->item(0), 'http://example.com');
970-
$this->assertEquals($form->getPhpValues(), ['example' => '']);
973+
$this->assertEquals(['example' => ''], $form->getPhpValues());
971974
}
972975

973976
public function testGetReturnTypes()

src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function testGetItem()
3838

3939
$cacheItem = $parserCacheAdapter->getItem($key);
4040

41-
$this->assertEquals($cacheItem->get(), $value);
42-
$this->assertEquals($cacheItem->isHit(), true);
41+
$this->assertEquals($value, $cacheItem->get());
42+
$this->assertTrue($cacheItem->isHit());
4343
}
4444

4545
public function testSave()

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,20 +592,20 @@ public function testSetCache()
592592

593593
$options = ['etag' => '"whatever"'];
594594
$response->setCache($options);
595-
$this->assertEquals($response->getEtag(), '"whatever"');
595+
$this->assertEquals('"whatever"', $response->getEtag());
596596

597597
$now = $this->createDateTimeNow();
598598
$options = ['last_modified' => $now];
599599
$response->setCache($options);
600-
$this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp());
600+
$this->assertEquals($now->getTimestamp(), $response->getLastModified()->getTimestamp());
601601

602602
$options = ['max_age' => 100];
603603
$response->setCache($options);
604-
$this->assertEquals($response->getMaxAge(), 100);
604+
$this->assertEquals(100, $response->getMaxAge());
605605

606606
$options = ['s_maxage' => 200];
607607
$response->setCache($options);
608-
$this->assertEquals($response->getMaxAge(), 200);
608+
$this->assertEquals(200, $response->getMaxAge());
609609

610610
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
611611
$this->assertFalse($response->headers->hasCacheControlDirective('private'));

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testRead()
102102
->method('findOne')
103103
->willReturnCallback(function ($criteria) use ($testTimeout) {
104104
$this->assertArrayHasKey($this->options['id_field'], $criteria);
105-
$this->assertEquals($criteria[$this->options['id_field']], 'foo');
105+
$this->assertEquals('foo', $criteria[$this->options['id_field']]);
106106

107107
$this->assertArrayHasKey($this->options['expiry_field'], $criteria);
108108
$this->assertArrayHasKey('$gte', $criteria[$this->options['expiry_field']]);

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public function testClear()
8787
$_SESSION['drak'] = 'loves symfony';
8888
$storage->getBag('attributes')->set('symfony', 'greatness');
8989
$key = $storage->getBag('attributes')->getStorageKey();
90-
$this->assertEquals($_SESSION[$key], ['symfony' => 'greatness']);
91-
$this->assertEquals($_SESSION['drak'], 'loves symfony');
90+
$this->assertEquals(['symfony' => 'greatness'], $_SESSION[$key]);
91+
$this->assertEquals('loves symfony', $_SESSION['drak']);
9292
$storage->clear();
93-
$this->assertEquals($_SESSION[$key], []);
94-
$this->assertEquals($_SESSION['drak'], 'loves symfony');
93+
$this->assertEquals([], $_SESSION[$key]);
94+
$this->assertEquals('loves symfony', $_SESSION['drak']);
9595
}
9696
}

src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class FilterControllerArgumentsEventTest extends TestCase
1212
public function testFilterControllerArgumentsEvent()
1313
{
1414
$filterController = new FilterControllerArgumentsEvent(new TestHttpKernel(), function () {}, ['test'], new Request(), 1);
15-
$this->assertEquals($filterController->getArguments(), ['test']);
15+
$this->assertEquals(['test'], $filterController->getArguments());
1616
}
1717
}

src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ public function testStoreTime()
205205

206206
$records = $this->storage->find('', '', 3, 'GET', $start, time() + 3 * 60);
207207
$this->assertCount(3, $records, '->find() returns all previously added records');
208-
$this->assertEquals($records[0]['token'], 'time_2', '->find() returns records ordered by time in descendant order');
209-
$this->assertEquals($records[1]['token'], 'time_1', '->find() returns records ordered by time in descendant order');
210-
$this->assertEquals($records[2]['token'], 'time_0', '->find() returns records ordered by time in descendant order');
208+
$this->assertEquals('time_2', $records[0]['token'], '->find() returns records ordered by time in descendant order');
209+
$this->assertEquals('time_1', $records[1]['token'], '->find() returns records ordered by time in descendant order');
210+
$this->assertEquals('time_0', $records[2]['token'], '->find() returns records ordered by time in descendant order');
211211

212212
$records = $this->storage->find('', '', 3, 'GET', $start, time() + 2 * 60);
213213
$this->assertCount(2, $records, '->find() should return only first two of the previously added records');

src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public function testLdapQueryScopeBase()
8787
$ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
8888

8989
$query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', [
90-
'scope' => Query::SCOPE_BASE,
90+
'scope' => Query::SCOPE_BASE,
9191
]);
9292
$result = $query->execute();
9393

9494
$entry = $result[0];
95-
$this->assertEquals($result->count(), 1);
95+
$this->assertEquals(1, $result->count());
9696
$this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn'));
9797
}
9898

@@ -109,7 +109,7 @@ public function testLdapQueryScopeOneLevel()
109109
$subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count();
110110

111111
$this->assertNotEquals($one_level_result->count(), $subtree_count);
112-
$this->assertEquals($one_level_result->count(), 1);
113-
$this->assertEquals($one_level_result[0]->getAttribute('ou'), ['Ldap']);
112+
$this->assertEquals(1, $one_level_result->count());
113+
$this->assertEquals(['Ldap'], $one_level_result[0]->getAttribute('ou'));
114114
}
115115
}

src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testLdapRename()
163163

164164
$result = $this->executeSearchQuery(1);
165165
$renamedEntry = $result[0];
166-
$this->assertEquals($renamedEntry->getAttribute('cn')[0], 'Kevin');
166+
$this->assertEquals('Kevin', $renamedEntry->getAttribute('cn')[0]);
167167

168168
$oldRdn = $entry->getAttribute('cn')[0];
169169
$entryManager->rename($renamedEntry, 'cn='.$oldRdn);

src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public function testFindArguments()
6262
$f = new PhpExecutableFinder();
6363

6464
if (\defined('HHVM_VERSION')) {
65-
$this->assertEquals($f->findArguments(), ['--php'], '::findArguments() returns HHVM arguments');
65+
$this->assertEquals(['--php'], $f->findArguments(), '::findArguments() returns HHVM arguments');
6666
} elseif ('phpdbg' === \PHP_SAPI) {
67-
$this->assertEquals($f->findArguments(), ['-qrr'], '::findArguments() returns phpdbg arguments');
67+
$this->assertEquals(['-qrr'], $f->findArguments(), '::findArguments() returns phpdbg arguments');
6868
} else {
69-
$this->assertEquals($f->findArguments(), [], '::findArguments() returns no arguments');
69+
$this->assertEquals([], $f->findArguments(), '::findArguments() returns no arguments');
7070
}
7171
}
7272
}

src/Symfony/Component/Templating/Tests/PhpEngineTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public function testGlobalsGetPassedToTemplate()
179179

180180
$this->loader->setTemplate('global.php', '<?php echo $global; ?>');
181181

182-
$this->assertEquals($engine->render('global.php'), 'global variable');
182+
$this->assertEquals('global variable', $engine->render('global.php'));
183183

184-
$this->assertEquals($engine->render('global.php', ['global' => 'overwritten']), 'overwritten');
184+
$this->assertEquals('overwritten', $engine->render('global.php', ['global' => 'overwritten']));
185185
}
186186

187187
public function testGetLoader()

src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ protected function validateMatrix($nplural, $matrix, $expectSuccess = true)
100100
foreach ($matrix as $langCode => $data) {
101101
$indexes = array_flip($data);
102102
if ($expectSuccess) {
103-
$this->assertEquals($nplural, \count($indexes), "Langcode '$langCode' has '$nplural' plural forms.");
103+
$this->assertCount((int) $nplural, $indexes, "Langcode '$langCode' has '$nplural' plural forms.");
104104
} else {
105-
$this->assertNotEquals((int) $nplural, \count($indexes), "Langcode '$langCode' has '$nplural' plural forms.");
105+
$this->assertNotCount((int) $nplural, $indexes, "Langcode '$langCode' has '$nplural' plural forms.");
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)