Skip to content

Commit

Permalink
Coding style: Apply automatic PHPCBF to tests forlder (PSR12)
Browse files Browse the repository at this point in the history
Related to #95
  • Loading branch information
ArthurHoaro committed Apr 5, 2021
1 parent e1847ae commit 0681511
Show file tree
Hide file tree
Showing 85 changed files with 561 additions and 500 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml
Expand Up @@ -5,7 +5,7 @@
<file>index.php</file>
<file>application</file>
<file>plugins</file>
<!-- <file>tests</file>-->
<file>tests</file>

<exclude-pattern>*/*.css</exclude-pattern>
<exclude-pattern>*/*.js</exclude-pattern>
Expand Down
10 changes: 5 additions & 5 deletions tests/PluginManagerTest.php
Expand Up @@ -39,7 +39,7 @@ public function setUp(): void
public function testPlugin(): void
{
PluginManager::$PLUGINS_PATH = self::$pluginPath;
$this->pluginManager->load(array(self::$pluginName));
$this->pluginManager->load([self::$pluginName]);

$this->assertTrue(function_exists('hook_test_random'));

Expand All @@ -50,19 +50,19 @@ public function testPlugin(): void
static::assertSame('woot', $data[1]);

$data = [0 => 'woot'];
$this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
$this->pluginManager->executeHooks('random', $data, ['target' => 'test']);

static::assertCount(2, $data);
static::assertSame('page test', $data[1]);

$data = [0 => 'woot'];
$this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
$this->pluginManager->executeHooks('random', $data, ['loggedin' => true]);

static::assertCount(2, $data);
static::assertEquals('loggedin', $data[1]);

$data = [0 => 'woot'];
$this->pluginManager->executeHooks('random', $data, array('loggedin' => null));
$this->pluginManager->executeHooks('random', $data, ['loggedin' => null]);

static::assertCount(3, $data);
static::assertEquals('loggedin', $data[1]);
Expand All @@ -76,7 +76,7 @@ public function testPlugin(): void
public function testPluginWithPhpError(): void
{
PluginManager::$PLUGINS_PATH = self::$pluginPath;
$this->pluginManager->load(array(self::$pluginName));
$this->pluginManager->load([self::$pluginName]);

$this->assertTrue(function_exists('hook_test_error'));

Expand Down
6 changes: 3 additions & 3 deletions tests/ThumbnailerTest.php
Expand Up @@ -103,10 +103,10 @@ protected function rrmdirContent($dir)
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (is_dir($dir."/".$object)) {
$this->rrmdirContent($dir."/".$object);
if (is_dir($dir . "/" . $object)) {
$this->rrmdirContent($dir . "/" . $object);
} else {
unlink($dir."/".$object);
unlink($dir . "/" . $object);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/TimeZoneTest.php
@@ -1,4 +1,5 @@
<?php

/**
* TimeZone's tests
*/
Expand Down
27 changes: 14 additions & 13 deletions tests/UtilsTest.php
@@ -1,4 +1,5 @@
<?php

/**
* Utilities' tests
*/
Expand Down Expand Up @@ -187,7 +188,7 @@ public function testGenerateLocation()
public function testGenerateLocationLoop()
{
$ref = 'http://localhost/?test';
$this->assertEquals('./?', generateLocation($ref, 'localhost', array('test')));
$this->assertEquals('./?', generateLocation($ref, 'localhost', ['test']));
}

/**
Expand Down Expand Up @@ -313,15 +314,15 @@ public function testReturnBytes()
*/
public function testHumanBytes()
{
$this->assertEquals('2'. t('kiB'), human_bytes(2 * 1024));
$this->assertEquals('2'. t('kiB'), human_bytes(strval(2 * 1024)));
$this->assertEquals('2'. t('MiB'), human_bytes(2 * (pow(1024, 2))));
$this->assertEquals('2'. t('MiB'), human_bytes(strval(2 * (pow(1024, 2)))));
$this->assertEquals('2'. t('GiB'), human_bytes(2 * (pow(1024, 3))));
$this->assertEquals('2'. t('GiB'), human_bytes(strval(2 * (pow(1024, 3)))));
$this->assertEquals('374'. t('B'), human_bytes(374));
$this->assertEquals('374'. t('B'), human_bytes('374'));
$this->assertEquals('232'. t('kiB'), human_bytes(237481));
$this->assertEquals('2' . t('kiB'), human_bytes(2 * 1024));
$this->assertEquals('2' . t('kiB'), human_bytes(strval(2 * 1024)));
$this->assertEquals('2' . t('MiB'), human_bytes(2 * (pow(1024, 2))));
$this->assertEquals('2' . t('MiB'), human_bytes(strval(2 * (pow(1024, 2)))));
$this->assertEquals('2' . t('GiB'), human_bytes(2 * (pow(1024, 3))));
$this->assertEquals('2' . t('GiB'), human_bytes(strval(2 * (pow(1024, 3)))));
$this->assertEquals('374' . t('B'), human_bytes(374));
$this->assertEquals('374' . t('B'), human_bytes('374'));
$this->assertEquals('232' . t('kiB'), human_bytes(237481));
$this->assertEquals(t('Unlimited'), human_bytes('0'));
$this->assertEquals(t('Unlimited'), human_bytes(0));
$this->assertEquals(t('Setting not set'), human_bytes(''));
Expand All @@ -332,9 +333,9 @@ public function testHumanBytes()
*/
public function testGetMaxUploadSize()
{
$this->assertEquals('1'. t('MiB'), get_max_upload_size(2097152, '1024k'));
$this->assertEquals('1'. t('MiB'), get_max_upload_size('1m', '2m'));
$this->assertEquals('100'. t('B'), get_max_upload_size(100, 100));
$this->assertEquals('1' . t('MiB'), get_max_upload_size(2097152, '1024k'));
$this->assertEquals('1' . t('MiB'), get_max_upload_size('1m', '2m'));
$this->assertEquals('100' . t('B'), get_max_upload_size(100, 100));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions tests/api/ApiMiddlewareTest.php
@@ -1,4 +1,5 @@
<?php

namespace Shaarli\Api;

use Shaarli\Config\ConfigManager;
Expand Down Expand Up @@ -80,7 +81,7 @@ public function testInvokeMiddlewareWithValidToken(): void
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/echo',
'HTTP_AUTHORIZATION'=> 'Bearer ' . ApiUtilsTest::generateValidJwtToken('NapoleonWasALizard'),
'HTTP_AUTHORIZATION' => 'Bearer ' . ApiUtilsTest::generateValidJwtToken('NapoleonWasALizard'),
]);
$request = Request::createFromEnvironment($env);
$response = new Response();
Expand Down Expand Up @@ -196,7 +197,7 @@ public function testInvokeMiddlewareNoSecretSetDebug()
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/echo',
'HTTP_AUTHORIZATION'=> 'Bearer jwt',
'HTTP_AUTHORIZATION' => 'Bearer jwt',
]);
$request = Request::createFromEnvironment($env);
$response = new Response();
Expand All @@ -219,7 +220,7 @@ public function testInvalidJwtAuthHeaderDebug()
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/echo',
'HTTP_AUTHORIZATION'=> 'PolarBearer jwt',
'HTTP_AUTHORIZATION' => 'PolarBearer jwt',
]);
$request = Request::createFromEnvironment($env);
$response = new Response();
Expand All @@ -245,7 +246,7 @@ public function testInvokeMiddlewareInvalidJwtDebug()
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/echo',
'HTTP_AUTHORIZATION'=> 'Bearer jwt',
'HTTP_AUTHORIZATION' => 'Bearer jwt',
]);
$request = Request::createFromEnvironment($env);
$response = new Response();
Expand Down
6 changes: 3 additions & 3 deletions tests/api/ApiUtilsTest.php
Expand Up @@ -32,10 +32,10 @@ public static function generateValidJwtToken($secret)
"alg": "HS512"
}');
$payload = Base64Url::encode('{
"iat": '. time() .'
"iat": ' . time() . '
}');
$signature = Base64Url::encode(hash_hmac('sha512', $header .'.'. $payload, $secret, true));
return $header .'.'. $payload .'.'. $signature;
$signature = Base64Url::encode(hash_hmac('sha512', $header . '.' . $payload, $secret, true));
return $header . '.' . $payload . '.' . $signature;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/api/controllers/info/InfoTest.php
@@ -1,4 +1,5 @@
<?php

namespace Shaarli\Api\Controllers;

use malkusch\lock\mutex\NoMutex;
Expand Down Expand Up @@ -106,7 +107,7 @@ public function testGetInfo()
$title = 'My bookmarks';
$headerLink = 'http://shaarli.tld';
$timezone = 'Europe/Paris';
$enabledPlugins = array('foo', 'bar');
$enabledPlugins = ['foo', 'bar'];
$defaultPrivateLinks = true;
$this->conf->set('general.title', $title);
$this->conf->set('general.header_link', $headerLink);
Expand Down
1 change: 0 additions & 1 deletion tests/api/controllers/links/DeleteLinkTest.php
@@ -1,6 +1,5 @@
<?php


namespace Shaarli\Api\Controllers;

use malkusch\lock\mutex\NoMutex;
Expand Down
3 changes: 2 additions & 1 deletion tests/api/controllers/links/GetLinksTest.php
@@ -1,4 +1,5 @@
<?php

namespace Shaarli\Api\Controllers;

use malkusch\lock\mutex\NoMutex;
Expand Down Expand Up @@ -329,7 +330,7 @@ public function testGetLinksSearchTerm()
// URL encoding
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => 'searchterm='. urlencode('@web')
'QUERY_STRING' => 'searchterm=' . urlencode('@web')
]);
$request = Request::createFromEnvironment($env);
$response = $this->controller->getLinks($request, new Response());
Expand Down
1 change: 0 additions & 1 deletion tests/api/controllers/links/PutLinkTest.php
@@ -1,6 +1,5 @@
<?php


namespace Shaarli\Api\Controllers;

use malkusch\lock\mutex\NoMutex;
Expand Down
1 change: 0 additions & 1 deletion tests/api/controllers/tags/DeleteTagTest.php
@@ -1,6 +1,5 @@
<?php


namespace Shaarli\Api\Controllers;

use malkusch\lock\mutex\NoMutex;
Expand Down
1 change: 1 addition & 0 deletions tests/api/controllers/tags/GetTagsTest.php
@@ -1,4 +1,5 @@
<?php

namespace Shaarli\Api\Controllers;

use malkusch\lock\mutex\NoMutex;
Expand Down
2 changes: 1 addition & 1 deletion tests/bookmark/BookmarkArrayTest.php
Expand Up @@ -185,7 +185,7 @@ public function testArrayAccessIterate()
$this->assertCount(3, $array);

foreach ($array as $id => $bookmark) {
$this->assertEquals(${'bookmark'. $id}, $bookmark);
$this->assertEquals(${'bookmark' . $id}, $bookmark);
}
}

Expand Down
7 changes: 4 additions & 3 deletions tests/bookmark/BookmarkFileServiceTest.php
@@ -1,4 +1,5 @@
<?php

/**
* Link datastore tests
*/
Expand Down Expand Up @@ -82,15 +83,15 @@ protected function setUp(): void
unlink(self::$testDatastore);
}

if (file_exists(self::$testConf .'.json.php')) {
unlink(self::$testConf .'.json.php');
if (file_exists(self::$testConf . '.json.php')) {
unlink(self::$testConf . '.json.php');
}

if (file_exists(self::$testUpdates)) {
unlink(self::$testUpdates);
}

copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
copy('tests/utils/config/configJson.json.php', self::$testConf . '.json.php');
$this->conf = new ConfigManager(self::$testConf);
$this->conf->set('resource.datastore', self::$testDatastore);
$this->conf->set('resource.updates', self::$testUpdates);
Expand Down
8 changes: 4 additions & 4 deletions tests/bookmark/BookmarkFilterTest.php
Expand Up @@ -417,28 +417,28 @@ public function testFilterCrossedSearch()
1,
count(self::$linkFilter->filter(
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
array($tags, $terms)
[$tags, $terms]
))
);
$this->assertEquals(
2,
count(self::$linkFilter->filter(
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
array('', $terms)
['', $terms]
))
);
$this->assertEquals(
1,
count(self::$linkFilter->filter(
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
array(false, 'PSR-2')
[false, 'PSR-2']
))
);
$this->assertEquals(
1,
count(self::$linkFilter->filter(
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
array($tags, '')
[$tags, '']
))
);
$this->assertEquals(
Expand Down
2 changes: 1 addition & 1 deletion tests/bookmark/BookmarkInitializerTest.php
Expand Up @@ -52,7 +52,7 @@ public function setUp(): void
unlink(self::$testDatastore);
}

copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
copy('tests/utils/config/configJson.json.php', self::$testConf . '.json.php');
$this->conf = new ConfigManager(self::$testConf);
$this->conf->set('resource.datastore', self::$testDatastore);
$this->pluginManager = new PluginManager($this->conf);
Expand Down
6 changes: 3 additions & 3 deletions tests/bookmark/BookmarkTest.php
Expand Up @@ -167,7 +167,7 @@ public function testValidateNotValidNoId()
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContainsPolyfill('- ID: '. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- ID: ' . PHP_EOL, $exception->getMessage());
}

/**
Expand All @@ -186,7 +186,7 @@ public function testValidateNotValidNoShortUrl()
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContainsPolyfill('- ShortUrl: '. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- ShortUrl: ' . PHP_EOL, $exception->getMessage());
}

/**
Expand All @@ -205,7 +205,7 @@ public function testValidateNotValidNoCreated()
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContainsPolyfill('- Created: '. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- Created: ' . PHP_EOL, $exception->getMessage());
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/bookmark/LinkUtilsTest.php
Expand Up @@ -142,7 +142,7 @@ public function testHtmlExtractExistentNameTag()
$this->assertEquals($description, html_extract_tag('description', $html));

// OpenGraph multiple properties both end with noise
$html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
$html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" ' .
'tag2="content2" content="' . $description . '" tag3="content3">';
$this->assertEquals($description, html_extract_tag('description', $html));

Expand All @@ -159,7 +159,7 @@ public function testHtmlExtractExistentNameTag()
$this->assertEquals($description, html_extract_tag('description', $html));

// OpenGraph reversed multiple properties both end with noise
$html = '<meta tag1="content1" content="' . $description . '" tag2="content2" '.
$html = '<meta tag1="content1" content="' . $description . '" tag2="content2" ' .
'property="og:unrelated1 og:description og:unrelated2" tag3="content3">';
$this->assertEquals($description, html_extract_tag('description', $html));

Expand All @@ -178,7 +178,7 @@ public function testHtmlExtractExistentNameTagWithMixedQuotes(): void
$html = '<meta property="og:description" content="' . $description . '">';
$this->assertEquals($description, html_extract_tag('description', $html));

$html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
$html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" ' .
'tag2="content2" content="' . $description . '" tag3="content3">';
$this->assertEquals($description, html_extract_tag('description', $html));

Expand All @@ -190,7 +190,7 @@ public function testHtmlExtractExistentNameTagWithMixedQuotes(): void
$html = '<meta property="og:description" content=\'' . $description . '\'>';
$this->assertEquals($description, html_extract_tag('description', $html));

$html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
$html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" ' .
'tag2="content2" content=\'' . $description . '\' tag3="content3">';
$this->assertEquals($description, html_extract_tag('description', $html));

Expand Down Expand Up @@ -247,9 +247,9 @@ public function testHtmlExtractNonExistentOgTag()

public function testHtmlExtractDescriptionFromGoogleRealCase(): void
{
$html = 'id="gsr"><meta content="Fêtes de fin d\'année" property="twitter:title"><meta '.
'content="Bonnes fêtes de fin d\'année ! #GoogleDoodle" property="twitter:description">'.
'<meta content="Bonnes fêtes de fin d\'année ! #GoogleDoodle" property="og:description">'.
$html = 'id="gsr"><meta content="Fêtes de fin d\'année" property="twitter:title"><meta ' .
'content="Bonnes fêtes de fin d\'année ! #GoogleDoodle" property="twitter:description">' .
'<meta content="Bonnes fêtes de fin d\'année ! #GoogleDoodle" property="og:description">' .
'<meta content="summary_large_image" property="twitter:card"><meta co'
;
$this->assertSame('Bonnes fêtes de fin d\'année ! #GoogleDoodle', html_extract_tag('description', $html));
Expand Down

0 comments on commit 0681511

Please sign in to comment.