Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T16427 logger interpolation #16429

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions tests/_support/Page/Http.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

namespace Page;

class Http
{
public const HTTP_103_EARLY_HINTS = 'HTTP/1.1 103 Early Hints';
public const HTTP_200_OK = 'HTTP/1.1 200 OK';
public const HTTP_302_FOUND = 'HTTP/1.1 302 Found';
public const HTTP_304_NOT_MODIFIED = 'HTTP/1.1 304 Not modified';
public const HTTP_404_NOT_FOUND = 'HTTP/1.1 404 Not Found';
public const HTTP_409_CONFLICT = 'HTTP/1.1 409 Conflict';
public const HTTP_418_IM_A_TEAPOT = "HTTP/1.1 418 I'm a teapot";

public const CODE_103 = 103;
public const CODE_200 = 200;
public const CODE_301 = 301;
public const CODE_304 = 304;
public const CODE_404 = 404;
public const CODE_409 = 409;
public const CODE_418 = 418;

public const CACHE_CONTROL = 'Cache-Control';
public const CACHE_MAX_AGE = 'max-age=3600';
public const CONFLICT = 'Conflict';
public const CONTENT_ENCODING = 'Content-Encoding';
public const CONTENT_ENCODING_GZIP = 'gzip';
public const CONTENT_LENGTH = 'Content-Length';
public const CONTENT_TYPE = 'Content-Type';
public const CONTENT_TYPE_CSV = 'text/csv';
public const CONTENT_TYPE_HTML = 'text/html';
public const CONTENT_TYPE_HTML_CHARSET = 'text/html; charset=UTF-8';
public const CONTENT_TYPE_HTML_RAW = 'Content-Type: text/html';
public const CONTENT_TYPE_JSON = 'application/json';
public const CONTENT_TYPE_JSON_UTF8 = 'application/json; charset=UTF-8';
public const CONTENT_TYPE_PLAIN = 'text/plain';
public const CONTENT_TYPE_PLAIN_RAW = 'Content-Type: text/plain';
public const CONTENT_TYPE_XHTML_XML = 'application/xhtml+xml';
public const ETAG = 'Etag';
public const EXPIRES = 'Expires';
public const LAST_MODIFIED = 'Last-Modified';
public const LOCATION = 'Location';
public const NO_CACHE = 'no-cache';
public const NOT_FOUND = 'Not Found';
public const NOT_MODIFIED = 'Not modified';
public const OK = 'OK';
public const REDIRECT_URI = 'new/place';
public const SERVER = 'Server';
public const STATUS = 'Status';
public const UTF8 = 'UTF-8';

public const DATETIME_FORMAT = 'D, d M Y H:i:s';

public const HOST_LOCALHOST = 'localhost';

public const METHOD_CONNECT = 'CONNECT';
public const METHOD_DELETE = 'DELETE';
public const METHOD_GET = 'GET';
public const METHOD_HEAD = 'HEAD';
public const METHOD_OPTIONS = 'OPTIONS';
public const METHOD_PATCH = 'PATCH';
public const METHOD_POST = 'POST';
public const METHOD_PURGE = 'PURGE';
public const METHOD_PUT = 'PUT';
public const METHOD_TRACE = 'TRACE';

public const MESSAGE_103_EARLY_HINTS = '103 Early Hints';
public const MESSAGE_200_OK = '200 OK';
public const MESSAGE_200_SUCCESS = '200 Success';
public const MESSAGE_301_MOVED_PERMANENTLY = '301 Moved Permanently';
public const MESSAGE_302_FOUND = '302 Found';
public const MESSAGE_304_NOT_MODIFIED = '304 Not modified';
public const MESSAGE_404_NOT_FOUND = '404 Not Found';
public const MESSAGE_409_CONFLICT = '409 Conflict';
public const MESSAGE_418_IM_A_TEAPOT = "418 I'm a teapot";

public const STREAM = 'php://input';
public const STREAM_MEMORY = 'php://memory';
public const STREAM_NAME = 'php';
public const STREAM_TEMP = 'php://temp';

public const TEST_CONTENT = '<h1>Money Doesn\'t Grow On Trees</h1>';
public const TEST_DOMAIN = 'phalcon.io';
public const TEST_IP_IPV6 = '2a00:8640:1::224:36ff:feef:1d89';
public const TEST_IP_ONE = '10.4.6.1';
public const TEST_IP_TWO = '10.4.6.2';
public const TEST_IP_THREE = '10.4.6.3';
public const TEST_IP_MULTI = '10.4.6.4,10.4.6.5';
public const TEST_URI = 'https://phalcon.io';
public const TEST_USER_AGENT = 'Chrome/Other 1.0.0';
}
3 changes: 2 additions & 1 deletion tests/unit/Assets/Collection/GetRealTargetPathCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function assetsCollectionGetRealTargetPath(UnitTester $I)
}

/**
* Tests Phalcon\Assets\Collection :: getRealTargetPath() - file does not exist
* Tests Phalcon\Assets\Collection :: getRealTargetPath() - file does not
* exist
*
* @param UnitTester $I
*
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Autoload/Loader/GetAddSetDirectoriesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class GetAddSetDirectoriesCest
use LoaderTrait;

/**
* Tests Phalcon\Autoload\Loader :: getDirectories()/addDirectory()/setDirectories()
* Tests Phalcon\Autoload\Loader ::
* getDirectories()/addDirectory()/setDirectories()
*
* @param UnitTester $I
*
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/Events/Manager/AttachCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function eventsManagerAttachByNameAfterDetatchAll(UnitTester $I)

$eventsManager->attach('log', $first);
$logListeners = $component->getEventsManager()
->getListeners('log');
->getListeners('log')
;
$I->assertCount(1, $logListeners);

$expected = OneListener::class;
Expand All @@ -73,7 +74,8 @@ public function eventsManagerAttachByNameAfterDetatchAll(UnitTester $I)
->attach('log', $second)
;
$logListeners = $component->getEventsManager()
->getListeners('log');
->getListeners('log')
;
$I->assertCount(2, $logListeners);

$expected = OneListener::class;
Expand All @@ -88,14 +90,16 @@ public function eventsManagerAttachByNameAfterDetatchAll(UnitTester $I)
->detachAll('log')
;
$logListeners = $component->getEventsManager()
->getListeners('log');
->getListeners('log')
;
$I->assertEmpty($logListeners);

$component->getEventsManager()
->attach('log', $second)
;
$logListeners = $component->getEventsManager()
->getListeners('log');
->getListeners('log')
;
$I->assertCount(1, $logListeners);

$expected = TwoListener::class;
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/Events/Manager/FireCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function eventsManagerFire(UnitTester $I)

$expected = ['three', 'two', 'one'];
$actual = $component->getEventsManager()
->getResponses();
->getResponses()
;
$I->assertSame($expected, $actual);
}

Expand Down Expand Up @@ -90,7 +91,8 @@ public function eventsManagerFireWithPriorities(UnitTester $I)

$expected = ['one', 'two', 'three'];
$actual = $component->getEventsManager()
->getResponses();
->getResponses()
;
$I->assertSame($expected, $actual);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Events/Manager/GetListenersCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function eventsManagerGetListeners(UnitTester $I)
$eventsManager->attach('log', $first);
$eventsManager->attach('log', $second);
$logListeners = $component->getEventsManager()
->getListeners('log');
->getListeners('log')
;
$I->assertCount(2, $logListeners);

$expected = OneListener::class;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Events/Manager/GetResponsesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function eventsManagerGetResponses(UnitTester $I)

$expected = ['one'];
$actual = $component->getEventsManager()
->getResponses();
->getResponses()
;
$I->assertSame($expected, $actual);
}
}
6 changes: 3 additions & 3 deletions tests/unit/Events/Manager/IsValidHandlerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function getExamples(): array
[
'string',
false,
'handler'
'handler',
],
[
'integer',
Expand All @@ -70,12 +70,12 @@ private function getExamples(): array
[
'callable - method',
true,
[$objectHandler, 'hasListeners']
[$objectHandler, 'hasListeners'],
],
[
'closure',
true,
$closureHandler
$closureHandler,
],
];
}
Expand Down
72 changes: 36 additions & 36 deletions tests/unit/Filter/Filter/SanitizeMultipleCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class SanitizeMultipleCest
* @param UnitTester $I
* @param Example $example
*
* @author Phalcon Team <team@phalcon.io>
* @since 2021-10-23
* @author Phalcon Team <team@phalcon.io>
* @since 2021-10-23
*/
public function filterFilterSanitize(UnitTester $I, Example $example)
{
Expand All @@ -47,7 +47,7 @@ public function filterFilterSanitize(UnitTester $I, Example $example)
$filters = $example['filters'];
$noRecursive = $example['noRecursive'];

$actual = $filter->sanitize($source, $filters, $noRecursive);
$actual = $filter->sanitize($source, $filters, $noRecursive);

$I->assertSame($expected, $actual);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public function filterFilterSanitizeCustomFilters(UnitTester $I, Example $exampl
$filter->set($name, $testFilter);
}

$actual = $filter->sanitize($source, array_keys($filters), $noRecursive);
$actual = $filter->sanitize($source, array_keys($filters), $noRecursive);

$I->assertSame($expected, $actual);
}
Expand All @@ -129,49 +129,49 @@ private function getFilterSanitizeExamples(): array
{
return [
[
'label' => 'null value',
'source' => null,
'filters' => [
'label' => 'null value',
'source' => null,
'filters' => [
'string',
'trim',
],
'noRecursive' => false,
'expected' => null,
'expected' => null,
],
[
'label' => 'string with filters',
'source' => ' lol<<< ',
'filters' => [
'label' => 'string with filters',
'source' => ' lol<<< ',
'filters' => [
'string',
'trim',
],
'noRecursive' => false,
'expected' => 'lol&lt;&lt;&lt;',
'expected' => 'lol&lt;&lt;&lt;',
],
[
'label' => 'array with filters',
'source' => [' 1 ', ' 2', '3 '],
'filters' => 'trim',
'label' => 'array with filters',
'source' => [' 1 ', ' 2', '3 '],
'filters' => 'trim',
'noRecursive' => false,
'expected' => ['1', '2', '3'],
'expected' => ['1', '2', '3'],
],
[
'label' => 'array with multiple filters',
'source' => [' <a href="a">1</a> ', ' <h1>2</h1>', '<p>3</p>'],
'filters' => ['striptags', 'trim'],
'label' => 'array with multiple filters',
'source' => [' <a href="a">1</a> ', ' <h1>2</h1>', '<p>3</p>'],
'filters' => ['striptags', 'trim'],
'noRecursive' => false,
'expected' => ['1', '2', '3'],
'expected' => ['1', '2', '3'],
],
[
'label' => 'multiple filters and more parameters',
'source' => ' mary had a little lamb ',
'filters' => [
'label' => 'multiple filters and more parameters',
'source' => ' mary had a little lamb ',
'filters' => [
'trim',
'replace' => [' ', '-'],
'remove' => ['mary'],
],
'noRecursive' => false,
'expected' => '-had-a-little-lamb',
'expected' => '-had-a-little-lamb',
],
];
}
Expand All @@ -183,24 +183,24 @@ private function getFilterSanitizeCustomFiltersExamples(): array
{
return [
[
'label' => 'no recursive array value with multiple sanitizers',
'source' => [4, 2, 0],
'filters' => [
'sum' => fn ($input) => array_sum($input),
'half' => fn ($input) => $input / 2,
'label' => 'no recursive array value with multiple sanitizers',
'source' => [4, 2, 0],
'filters' => [
'sum' => fn($input) => array_sum($input),
'half' => fn($input) => $input / 2,
],
'noRecursive' => true,
'expected' => 3,
'expected' => 3,
],
[
'label' => 'recursive array value with multiple sanitizers',
'source' => [4, 2, 0],
'filters' => [
'double' => fn ($input) => $input * 2,
'inverse' => fn ($input) => 0 - $input,
'label' => 'recursive array value with multiple sanitizers',
'source' => [4, 2, 0],
'filters' => [
'double' => fn($input) => $input * 2,
'inverse' => fn($input) => 0 - $input,
],
'noRecursive' => false,
'expected' => [-8, -4, 0],
'expected' => [-8, -4, 0],
],
];
}
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/Filter/SanitizeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,10 @@ private function getExamples(): array
'class' => 'email',
'label' => 'email()',
'method' => 'email',
'source' => ["!(first.guy)
@*my-domain**##.com.rx//"],
'source' => [
"!(first.guy)
@*my-domain**##.com.rx//",
],
'expected' => "!first.guy@*my-domain**##.com.rx",
],
[
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/Html/Escaper/AttributesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ class AttributesCest
*/
public function escaperAttributes(UnitTester $I, Example $example)
{
$I->wantToTest('Escaper - attributes()');

$escaper = new Escaper();

$text = $example['text'];
$flags = $example['htmlQuoteType'];

$I->wantToTest(
'Escaper - attributes() - ' . $flags
);

$escaper = new Escaper();
$escaper->setFlags($flags);

$expected = $example['expected'];
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Html/Escaper/GetSetFlagsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function escaperGetSetFlags(UnitTester $I)
$actual = $escaper->getFlags();
$I->assertSame($expected, $actual);

$expected = 'That&#039;s right';
$actual = $escaper->attributes("That's right");
$I->assertSame($expected, $actual);

$escaper->setFlags(ENT_HTML401);

$expected = ENT_HTML401;
Expand Down
Loading
Loading