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

Fix/reporting warnings #9

Merged
merged 2 commits into from
Apr 30, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->
## Unreleased
- Ignore warning in parsing HTML

## 7.5.0 - 2023-11-29
- Fix finding html tags when there are encoded html entities
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"phpstan/phpstan": "^1.8.0",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpunit/phpunit": "^9.5.20"
"phpunit/phpunit": "^10.5.20"
},
"autoload": {
"psr-4": {
Expand Down
27 changes: 13 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" colors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
bootstrap="vendor/autoload.php">

<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/DependencyInjection</directory>
<directory>src/Exception</directory>
<directory>src/Resources</directory>
<directory suffix="Bundle.php">src/*</directory>
</exclude>
<report>
<clover outputFile="./code-coverage/clover.xml"/>
<html outputDirectory="./code-coverage" highLowerBound="90"/>
</report>
</coverage>

<testsuites>
<testsuite name="VysokeSkoly/UtilsBundle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<logging>
<junit outputFile="./code-coverage/junit.xml"/>
</logging>

<php>
<!-- E_ALL = 30719 -->
<ini name="error_reporting" value="30719"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/DependencyInjection</directory>
<directory>src/Exception</directory>
<directory>src/Resources</directory>
<directory suffix="Bundle.php">src/*</directory>
</exclude>
</source>
</phpunit>
3 changes: 3 additions & 0 deletions src/Service/HtmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function xpathHtmlDocument(string $content, string $xpathQuery): ISeq
$htmlContent = $this->transformUnsupportedHtml($content);
$htmlContent = $this->encodeHtml($htmlContent);

// @see https://stackoverflow.com/questions/11819603/domdocument-loadhtml-doesnt-work-properly-on-a-server
$previously = libxml_use_internal_errors(true);

// @see https://www.php.net/manual/en/domdocument.loadhtml.php#95251
$dom = new \DOMDocument();
$dom->loadHTML(sprintf('<?xml encoding="UTF-8">%s', $htmlContent));
Expand Down
2 changes: 1 addition & 1 deletion tests/Entity/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testShouldGetMimeType(string $extension, string $expected): void
$this->assertSame($expected, $result);
}

public function provideExtension(): array
public static function provideExtension(): array
{
return [
// extension, expected mime type
Expand Down
2 changes: 1 addition & 1 deletion tests/Entity/LetterItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testShouldGetLetterInUpperCase(string $letter, string $expected)
$this->assertSame($expected, $letter->getLetter());
}

public function provideLetter(): array
public static function provideLetter(): array
{
return [
// letter, expected
Expand Down
2 changes: 1 addition & 1 deletion tests/Service/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testShouldCreateAlphabeticalList(array $items, string $column, a
$this->assertEquals($expected, ArrayHelper::getAlphabeticalList($items, $column));
}

public function provideAplhabeticalList(): array
public static function provideAplhabeticalList(): array
{
return [
// items, column, expected
Expand Down
2 changes: 1 addition & 1 deletion tests/Service/DebugLevelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testShouldCheckAllDebugModes(
$this->assertSame($isCacheEnabled, $this->debugLevel->isCacheEnabled());
}

public function provideLevel(): array
public static function provideLevel(): array
{
return [
// debug level, expected debug level, is debug?, is cache enabled?
Expand Down
45 changes: 31 additions & 14 deletions tests/Service/HtmlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function setUp(): void
}

/**
* @dataProvider imagesProvider
* @dataProvider provideImages
*/
public function testShouldGetImages(string $content, array $expectedImages): void
{
Expand All @@ -32,7 +32,7 @@ public function testShouldGetImages(string $content, array $expectedImages): voi
}
}

public function imagesProvider(): array
public static function provideImages(): array
{
return [
// content, imageSources
Expand Down Expand Up @@ -125,11 +125,28 @@ class="wp-image-19"
),
],
],
'html with warning' => [
'<p>Text</strong></p>
<h3><strong><a title="Průzkum: Studium za pandemie" href="https://go.minute.app/#R/studovatzapandemie" target="_blank" rel="noopener">&gt;&gt; ZAPOJIT SE DO PRŮZKUMU ZDE &lt;&lt;</a></strong></h3>
<p>Text 2.</p>
<p><img class="wp-image-30584 alignleft" src="http://vs-admin.prod/wp-content/uploads/2021/05/apple-min_600.png" alt="apple-vyhra_vysokeskoly" width="294" height="321" /><br />Text:  with space</p>',
[
' class="wp-image-30584 alignleft" src="http://vs-admin.prod/wp-content/uploads/2021/05/apple-min_600.png" alt="apple-vyhra_vysokeskoly" width="294" height="321" /' => new Image(
[
'class' => 'wp-image-30584 alignleft',
'src' => 'http://vs-admin.prod/wp-content/uploads/2021/05/apple-min_600.png',
'alt' => 'apple-vyhra_vysokeskoly',
'width' => '294',
'height' => '321',
],
),
],
],
];
}

/**
* @dataProvider tagProvider
* @dataProvider provideTags
*/
public function testShouldTransformToHtmlTag(
string $tag,
Expand All @@ -140,7 +157,7 @@ public function testShouldTransformToHtmlTag(
$this->assertSame($expected, $this->htmlHelper->transformToTag($tag, $parameters, $isSingleTag));
}

public function tagProvider(): array
public static function provideTags(): array
{
return [
// tag, parameters, isSingleTag, expected
Expand Down Expand Up @@ -180,7 +197,7 @@ public function testShouldReplaceAllImageSourcesInContent(): void
}

/**
* @dataProvider linksProvider
* @dataProvider provideLinks
*/
public function testShouldGetAllLinksFromContent(string $content, array $expectedLinks): void
{
Expand All @@ -193,7 +210,7 @@ public function testShouldGetAllLinksFromContent(string $content, array $expecte
}
}

public function linksProvider(): array
public static function provideLinks(): array
{
return [
// content, expectedLinks
Expand Down Expand Up @@ -346,7 +363,7 @@ public function testShouldGetAllParagraphsFromHtml(): void
}

/**
* @dataProvider firstReplacementProvider
* @dataProvider provideFirstReplacement
*/
public function testShouldInsertTextAfterFirstOccurrence(
string $content,
Expand All @@ -357,7 +374,7 @@ public function testShouldInsertTextAfterFirstOccurrence(
$this->assertSame($expectedContent, $this->htmlHelper->insertAfterFirst($content, $replacement, $search));
}

public function firstReplacementProvider(): array
public static function provideFirstReplacement(): array
{
return [
// content, replacement, search for, expected replaced content
Expand All @@ -371,8 +388,8 @@ public function firstReplacementProvider(): array
'<p> </p>' .
'<p>Last paragraph</p>',
'replacement' => '{-top-}',
'search for' => '<p> </p>',
'expected' => '<p>Žluťoučký kůň se pase 🐴</p>' .
'search' => '<p> </p>',
'expectedContent' => '<p>Žluťoučký kůň se pase 🐴</p>' .
'<p> </p>{-top-}' .
'<p>Second paragraph</p>' .
'<p> </p>' .
Expand All @@ -382,7 +399,7 @@ public function firstReplacementProvider(): array
}

/**
* @dataProvider lastReplacementProvider
* @dataProvider provideLastReplacement
*/
public function testShouldInsertTextAfterLastOccurrence(
string $content,
Expand All @@ -393,7 +410,7 @@ public function testShouldInsertTextAfterLastOccurrence(
$this->assertSame($expectedContent, $this->htmlHelper->insertAfterLast($content, $replacement, $search));
}

public function lastReplacementProvider(): array
public static function provideLastReplacement(): array
{
return [
// content, replacement, search for, expected replaced content
Expand All @@ -408,8 +425,8 @@ public function lastReplacementProvider(): array
'<p> </p>' .
'<p>Last paragraph</p>',
'replacement' => '{-bottom-}',
'search for' => '<p> </p>',
'expected' => '<p>Žluťoučký kůň se pase 🐴</p>' .
'search' => '<p> </p>',
'expectedContent' => '<p>Žluťoučký kůň se pase 🐴</p>' .
'<p> </p>' .
'<p>Second paragraph</p>' .
'<p> </p>{-bottom-}' .
Expand Down
2 changes: 1 addition & 1 deletion tests/Service/RegexHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testShouldParseMatchFromString(string $string, string $pattern,
$this->assertSame($expected, RegexHelper::parse($string, $pattern));
}

public function provideToParse(): array
public static function provideToParse(): array
{
return [
'empty' => ['', '/(w+)/', null],
Expand Down
12 changes: 6 additions & 6 deletions tests/Service/StringUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testShouldValidateEmails(string $email, bool $isValid): void
}
}

public function provideEmail(): array
public static function provideEmail(): array
{
return [
['email@domain.com', true],
Expand Down Expand Up @@ -89,7 +89,7 @@ public function testShouldFormatPhoneNumber(string $expected, string $given): vo
$this->assertEquals($expected, StringUtils::formatPhoneNumber($given));
}

public function providePhoneNumbers(): array
public static function providePhoneNumbers(): array
{
return [
['+420 123 456 789', '+420123456789'],
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testShouldDetectIfStringStartsWith(string $haystack, string $nee
$this->assertSame($expectedResult, StringUtils::startsWith($haystack, $needle));
}

public function provideForStartsWith(): array
public static function provideForStartsWith(): array
{
return [
// $haystack, $needle, $expectedResult
Expand All @@ -175,7 +175,7 @@ public function testShouldDetectIfStringEndsWith(string $haystack, string $needl
$this->assertSame($expectedResult, StringUtils::endsWith($haystack, $needle));
}

public function provideForEndsWith(): array
public static function provideForEndsWith(): array
{
return [
// $haystack, $needle, $expectedResult
Expand All @@ -200,7 +200,7 @@ public function testShouldGetFirstLetter(string $string, string $expected): void
$this->assertEquals($expected, StringUtils::getFirstLetter($string));
}

public function provideFirstLetter(): array
public static function provideFirstLetter(): array
{
return [
'empty' => ['', ''],
Expand All @@ -221,7 +221,7 @@ public function testShouldContainsAString(string $heystack, string $needle, bool
$this->assertSame($expected, StringUtils::contains($heystack, $needle));
}

public function provideForContains(): array
public static function provideForContains(): array
{
return [
// heystack, needle, expected
Expand Down
6 changes: 3 additions & 3 deletions tests/Service/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testBuildUrl(string $expectedUrl, string $url, array $params): v
$this->assertEquals($expectedUrl, Url::buildUrlWithParams($url, $params));
}

public function provideUrlForBuild(): array
public static function provideUrlForBuild(): array
{
return [
// url without params in it and without additional params
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testShouldRemoveParameterIfItIsPresent(string $originalUrl, stri
$this->assertSame($expectedUrl, Url::removeParam($originalUrl, $parameterToRemove));
}

public function provideParameterForRemove(): array
public static function provideParameterForRemove(): array
{
return [
// Standard URL with primitive param to be removed from multiple parameters
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testShouldRetrievesParametersFromUrlToArray(string $url, array $
$this->assertSame($expectedValue, Url::getParams($url));
}

public function provideUrlParameter(): array
public static function provideUrlParameter(): array
{
return [
['http://www.vysokeskoly.cz/search/?foo=bar', ['foo' => 'bar']],
Expand Down
4 changes: 2 additions & 2 deletions tests/Service/XmlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testShouldGetAttributeValueFromXml(string $attributeName, ?strin
$this->assertSame($expected, XmlHelper::getXmlAttributeValue($this->xml, $attributeName));
}

public function provideAttributes(): array
public static function provideAttributes(): array
{
return [
'existing' => ['totalCount', '123'],
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testShouldSanitizeXml(string $inputXmlPart, string $expectedOutp
$this->assertSame($expectedOutput, XmlHelper::sanitizeXml($input));
}

public function provideXmlData(): array
public static function provideXmlData(): array
{
return [
['Text with completely valid characters ĎŤŇŠŘÜÚ', 'Text with completely valid characters ĎŤŇŠŘÜÚ'],
Expand Down
Loading