Skip to content

Commit

Permalink
[phpcs] fixed the phpunit test files
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Dec 17, 2023
1 parent 6acbd6a commit 4de09a8
Show file tree
Hide file tree
Showing 346 changed files with 4,419 additions and 6,191 deletions.
9 changes: 3 additions & 6 deletions tests/PhpUnitSfTestHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

trait PhpUnitSfTestHelperTrait
{
public function diag($message): void
{

}
public function diag($message): void {}

public function arrays_are_equal($actual, $expected, string $message = ''): void
{
Expand Down Expand Up @@ -50,12 +47,12 @@ public function ok($actual, string $message = ''): void

public function isa_ok($actual, $expected, string $message = ''): void
{
if ($expected === 'array') {
if ('array' === $expected) {
$this->assertIsArray($actual, $message);
} elseif (str_starts_with($expected, 'sf')) {
$this->assertInstanceOf($expected, $actual, $message);
} else {
throw new \RuntimeException('unhandled type: '. $expected);
throw new \RuntimeException('unhandled type: '.$expected);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/action/sfComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class sfComponentTest extends sfEventDispatcherTestCase

public function setUp(): void
{
$this->context = sfContext::getInstance([
$this->context = sfContext::getInstance(array(
'routing' => 'sfNoRouting',
'request' => 'sfWebRequest',
]);
));

$this->testObject = new myComponent($this->context, 'module', 'action');
$this->dispatcher = $this->context->getEventDispatcher();
Expand Down Expand Up @@ -70,8 +70,8 @@ public function testSetter()
{
$component = new myComponent($this->context, 'module', 'action');

$component->foo = [];
$component->foo = array();
$component->foo[] = 'bar';
$this->assertSame(['bar'], $component->foo, '__set() populates component variables');
$this->assertSame(array('bar'), $component->foo, '__set() populates component variables');
}
}
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function sf_unit_test_shutdown()
$sessions = glob(sys_get_temp_dir().'/sessions*');
$tmp_files = glob(sys_get_temp_dir().'/sf*');

$files = array_merge(empty($sessions) ? [] : $sessions, empty($tmp_files) ? [] : $tmp_files);
$files = array_merge(empty($sessions) ? array() : $sessions, empty($tmp_files) ? array() : $tmp_files);
foreach ($files as $file) {
if (is_dir($file)) {
sfToolkit::clearDirectory($file);
Expand All @@ -61,5 +61,5 @@ function sf_unit_test_shutdown()
// Helper for cross platform testcases that validate output
function fix_linebreaks($content)
{
return str_replace(["\r\n", "\n", "\r"], "\n", $content);
return str_replace(array("\r\n", "\n", "\r"), "\n", $content);
}
24 changes: 12 additions & 12 deletions tests/cache/CacheDriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ public function testRemovePattern(string $pattern, array $results)

public function removePatternDataProvider(): Generator
{
yield ['*:bar:foo', [false, false, true, true]];
yield ['foo:bar:*', [false, true, false, true]];
yield ['foo:**:foo', [false, true, true, true]];
yield ['foo:bar:**', [false, true, false, false]];
yield ['**:bar', [true, true, true, false]];
yield ['**', [false, false, false, false]];
yield array('*:bar:foo', array(false, false, true, true));
yield array('foo:bar:*', array(false, true, false, true));
yield array('foo:**:foo', array(false, true, true, true));
yield array('foo:bar:**', array(false, true, false, false));
yield array('**:bar', array(true, true, true, false));
yield array('**', array(false, false, false, false));
}

public function testGetTimeout()
{
foreach ([86400, 10] as $lifetime) {
foreach (array(86400, 10) as $lifetime) {
$this->cache->set('foo', 'bar', $lifetime);

$delta = $this->cache->getTimeout('foo') - time();
Expand All @@ -136,7 +136,7 @@ public function testGetTimeout()
$this->cache->set('bar', 'foo', -10);
$this->assertSame($this->cache->getTimeout('bar'), 0, '->getTimeout() returns the timeout time for a given cache key');

foreach ([86400, 10] as $lifetime) {
foreach (array(86400, 10) as $lifetime) {
$this->cache->setOption('lifetime', $lifetime);
$this->cache->set('foo', 'bar');

Expand All @@ -149,7 +149,7 @@ public function testGetTimeout()

public function testGetLastModified()
{
foreach ([86400, 10] as $lifetime) {
foreach (array(86400, 10) as $lifetime) {
$this->cache->set('bar', 'foo', $lifetime);
$now = time();
$lastModified = $this->cache->getLastModified('bar');
Expand All @@ -159,7 +159,7 @@ public function testGetLastModified()
$this->cache->set('bar', 'foo', -10);
$this->assertSame(0, $this->cache->getLastModified('bar'), '->getLastModified() returns the last modified time for a given cache key');

foreach ([86400, 10] as $lifetime) {
foreach (array(86400, 10) as $lifetime) {
$this->cache->setOption('lifetime', $lifetime);
$this->cache->set('bar', 'foo');

Expand All @@ -178,9 +178,9 @@ public function testGetMany()
$this->cache->set('bar', 'foo');
$this->cache->set('foo', 'bar');

$result = $this->cache->getMany(['foo', 'bar']);
$result = $this->cache->getMany(array('foo', 'bar'));
asort($result);
$this->assertSame(['foo', 'bar'], array_keys($result), '->getMany() gets many keys in one call');
$this->assertSame(array('foo', 'bar'), array_keys($result), '->getMany() gets many keys in one call');
$this->assertSame('bar', $result['foo'], '->getMany() gets many keys in one call');
$this->assertSame('foo', $result['bar'], '->getMany() gets many keys in one call');

Expand Down
2 changes: 1 addition & 1 deletion tests/cache/sfCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class sfCacheTest extends TestCase
public function testInitialize()
{
$cache = new myCache();
$cache->initialize(['foo' => 'bar']);
$cache->initialize(array('foo' => 'bar'));
$this->assertSame('bar', $cache->getOption('foo'), '->initialize() takes an array of options as its first argument');
}
}
4 changes: 2 additions & 2 deletions tests/cache/sfFileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function setUp(): void
unlink($temp);
mkdir($temp);

$this->cache = new sfFileCache([
$this->cache = new sfFileCache(array(
'cache_dir' => $temp,
]);
));
}

protected function tearDown(): void
Expand Down
12 changes: 6 additions & 6 deletions tests/cache/sfFunctionCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function testFunction()
$result = testFunctionCache(1, 2);

$this->assertSame('121', $result);
$this->assertSame('122', $functionCache->call('testFunctionCache', [1, 2]), $result, '->call() works with functions');
$this->assertSame('122', $functionCache->call('testFunctionCache', [1, 2]), $result, '->call() stores the function call in cache');
$this->assertSame('122', $functionCache->call('testFunctionCache', array(1, 2)), $result, '->call() works with functions');
$this->assertSame('122', $functionCache->call('testFunctionCache', array(1, 2)), $result, '->call() stores the function call in cache');
}

public function testClassStaticMethod()
Expand All @@ -41,9 +41,9 @@ public function testClassStaticMethod()
$result = testFunctionCache::testStatic(1, 2);

$this->assertSame(1, testFunctionCache::$count);
$this->assertSame($result, $functionCache->call([testFunctionCache::class, 'testStatic'], [1, 2]), '->call() works with static method calls');
$this->assertSame($result, $functionCache->call(array(testFunctionCache::class, 'testStatic'), array(1, 2)), '->call() works with static method calls');
$this->assertSame(2, testFunctionCache::$count);
$this->assertSame($result, $functionCache->call([testFunctionCache::class, 'testStatic'], [1, 2]), '->call() stores the function call in cache');
$this->assertSame($result, $functionCache->call(array(testFunctionCache::class, 'testStatic'), array(1, 2)), '->call() stores the function call in cache');
$this->assertSame(2, testFunctionCache::$count);
}

Expand All @@ -58,9 +58,9 @@ public function testClassNonStaticMethod()
$result = $object->test(1, 2);

$this->assertSame(1, testFunctionCache::$count);
$this->assertSame($result, $functionCache->call([$object, 'test'], [1, 2]), '->call() works with object methods');
$this->assertSame($result, $functionCache->call(array($object, 'test'), array(1, 2)), '->call() works with object methods');
$this->assertSame(2, testFunctionCache::$count);
$this->assertSame($result, $functionCache->call([$object, 'test'], [1, 2]), '->call() stores the function call in cache');
$this->assertSame($result, $functionCache->call(array($object, 'test'), array(1, 2)), '->call() stores the function call in cache');
$this->assertSame(2, testFunctionCache::$count);
}
}
4 changes: 2 additions & 2 deletions tests/cache/sfMemcacheCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function setUp(): void
$memcachedHost = null;
}

$this->cache = new sfMemcacheCache([
$this->cache = new sfMemcacheCache(array(
'storeCacheInfo' => true,
'host' => $memcachedHost,
]);
));
}

public function testRemove()
Expand Down
2 changes: 1 addition & 1 deletion tests/cache/sfSQLiteCacheFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function setUp(): void
{
$database = tempnam(sys_get_temp_dir(), 'file_cache_temp_');
unlink($database);
$this->cache = new sfSQLiteCache(['database' => $database]);
$this->cache = new sfSQLiteCache(array('database' => $database));
}

protected function tearDown(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/cache/sfSQLiteCacheMemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class sfSQLiteCacheMemoryTest extends CacheDriverTestCase
{
public function setUp(): void
{
$this->cache = new sfSQLiteCache(['database' => ':memory:']);
$this->cache = new sfSQLiteCache(array('database' => ':memory:'));
}
}
42 changes: 21 additions & 21 deletions tests/command/sfCommandArgumentSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function testConstruct()
{
$argumentSet = new sfCommandArgumentSet();

$this->assertSame([], $argumentSet->getArguments(), '__construct() creates a new sfCommandArgumentSet object');
$this->assertSame(array(), $argumentSet->getArguments(), '__construct() creates a new sfCommandArgumentSet object');

$foo = new sfCommandArgument('foo');
$bar = new sfCommandArgument('bar');
$argumentSet = new sfCommandArgumentSet([$foo, $bar]);
$this->assertSame(['foo' => $foo, 'bar' => $bar], $argumentSet->getArguments(), '__construct() takes an array of sfCommandArgument objects as its first argument');
$argumentSet = new sfCommandArgumentSet(array($foo, $bar));
$this->assertSame(array('foo' => $foo, 'bar' => $bar), $argumentSet->getArguments(), '__construct() takes an array of sfCommandArgument objects as its first argument');
}

public function testSetArguments()
Expand All @@ -35,11 +35,11 @@ public function testSetArguments()
$bar = new sfCommandArgument('bar');

$argumentSet = new sfCommandArgumentSet();
$argumentSet->setArguments([$foo]);
$this->assertSame(['foo' => $foo], $argumentSet->getArguments(), '->setArguments() sets the array of sfCommandArgument objects');
$argumentSet->setArguments(array($foo));
$this->assertSame(array('foo' => $foo), $argumentSet->getArguments(), '->setArguments() sets the array of sfCommandArgument objects');

$argumentSet->setArguments([$bar]);
$this->assertSame(['bar' => $bar], $argumentSet->getArguments(), '->setArguments() clears all sfCommandArgument objects');
$argumentSet->setArguments(array($bar));
$this->assertSame(array('bar' => $bar), $argumentSet->getArguments(), '->setArguments() clears all sfCommandArgument objects');
}

public function testAddArgument()
Expand All @@ -48,11 +48,11 @@ public function testAddArgument()
$bar = new sfCommandArgument('bar');

$argumentSet = new sfCommandArgumentSet();
$argumentSet->addArguments([$foo]);
$this->assertSame(['foo' => $foo], $argumentSet->getArguments(), '->addArguments() adds an array of sfCommandArgument objects');
$argumentSet->addArguments(array($foo));
$this->assertSame(array('foo' => $foo), $argumentSet->getArguments(), '->addArguments() adds an array of sfCommandArgument objects');

$argumentSet->addArguments([$bar]);
$this->assertSame(['foo' => $foo, 'bar' => $bar], $argumentSet->getArguments(), '->addArguments() does not clear existing sfCommandArgument objects');
$argumentSet->addArguments(array($bar));
$this->assertSame(array('foo' => $foo, 'bar' => $bar), $argumentSet->getArguments(), '->addArguments() does not clear existing sfCommandArgument objects');
}

public function testConflictNames()
Expand All @@ -61,7 +61,7 @@ public function testConflictNames()
$foo2 = new sfCommandArgument('foo');

$argumentSet = new sfCommandArgumentSet();
$argumentSet->addArguments([$foo]);
$argumentSet->addArguments(array($foo));

$this->expectException(sfCommandException::class);
$argumentSet->addArgument($foo2);
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testGetArgument()
$foo = new sfCommandArgument('foo');

$argumentSet = new sfCommandArgumentSet();
$argumentSet->addArguments([$foo]);
$argumentSet->addArguments(array($foo));

$this->assertSame($foo, $argumentSet->getArgument('foo'), '->getArgument() returns a sfCommandArgument by its name');

Expand All @@ -106,7 +106,7 @@ public function testHasArgument()
$foo = new sfCommandArgument('foo');

$argumentSet = new sfCommandArgumentSet();
$argumentSet->addArguments([$foo]);
$argumentSet->addArguments(array($foo));
$this->assertSame($argumentSet->hasArgument('foo'), true, '->hasArgument() returns true if a sfCommandArgument exists for the given name');
$this->assertSame($argumentSet->hasArgument('bar'), false, '->hasArgument() returns false if a sfCommandArgument exists for the given name');
}
Expand Down Expand Up @@ -140,18 +140,18 @@ public function testGetArgumentCount()
public function testGetDefaults()
{
$argumentSet = new sfCommandArgumentSet();
$argumentSet->addArguments([
$argumentSet->addArguments(array(
new sfCommandArgument('foo1', sfCommandArgument::OPTIONAL),
new sfCommandArgument('foo2', sfCommandArgument::OPTIONAL, '', 'default'),
new sfCommandArgument('foo3', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY),
// new sfCommandArgument('foo4', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, '', array(1, 2)),
]);
$this->assertSame($argumentSet->getDefaults(), ['foo1' => null, 'foo2' => 'default', 'foo3' => []], '->getDefaults() return the default values for each argument');
));
$this->assertSame($argumentSet->getDefaults(), array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), '->getDefaults() return the default values for each argument');

$argumentSet = new sfCommandArgumentSet();
$argumentSet->addArguments([
new sfCommandArgument('foo4', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, '', [1, 2]),
]);
$this->assertSame($argumentSet->getDefaults(), ['foo4' => [1, 2]], '->getDefaults() return the default values for each argument');
$argumentSet->addArguments(array(
new sfCommandArgument('foo4', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, '', array(1, 2)),
));
$this->assertSame($argumentSet->getDefaults(), array('foo4' => array(1, 2)), '->getDefaults() return the default values for each argument');
}
}
4 changes: 2 additions & 2 deletions tests/command/sfCommandArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function testSetDefault()
$this->assertSame($argument->getDefault(), 'another', '->setDefault() changes the default value');

$argument = new sfCommandArgument('foo', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY);
$argument->setDefault([1, 2]);
$this->assertSame([1, 2], $argument->getDefault(), '->setDefault() changes the default value');
$argument->setDefault(array(1, 2));
$this->assertSame(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value');
}

public function testDefaultValueForRequired()
Expand Down
Loading

0 comments on commit 4de09a8

Please sign in to comment.