Skip to content

Commit 3bf1787

Browse files
committed
Fixed CI
1 parent cf7bc4f commit 3bf1787

File tree

10 files changed

+38
-48
lines changed

10 files changed

+38
-48
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
coverage: xdebug
7979

8080
- name: Generate Locale (for tests)
81-
run: sudo locale-gen de_DE.UTF-8
81+
run: sudo locale-gen de_DE.UTF-8 && sudo update-locale
8282

8383
- uses: actions/checkout@v2
8484

.gitignore

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
1-
.DS_Store
2-
._*
3-
.Spotlight-V100
4-
.Trashes
5-
Thumbs.db
6-
Desktop.ini
7-
.idea
8-
build/
9-
phpunit.xml
10-
composer.phar
11-
vendor
12-
*.settings
13-
*.project
14-
*.buildpath
15-
16-
/samples/results
17-
/phpunit.bat
18-
/todo.txt
19-
/samples/Sample_00_Test.php
20-
/samples/#47
21-
/samples/#70
22-
/samples/#71
23-
/samples/Github_*.*
24-
/samples/#83/*.lnk
1+
## PHPCSFixer
2+
/.php-cs-fixer.cache
3+
## PHPUnit
4+
/.phpunit.result.cache
5+
## Dependencies
256
/composer.lock
26-
27-
/.php-cs-fixer.cache
7+
/vendor/

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": ["PHP","Office","Common","component"],
55
"homepage": "http://phpoffice.github.io",
66
"type": "library",
7-
"license": "LGPL",
7+
"license": "LGPL-3.0-only",
88
"authors": [
99
{
1010
"name": "Mark Baker"
@@ -19,8 +19,7 @@
1919
"pclzip/pclzip": "^2.8"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^4.8.36 || ^7.0",
23-
"phpdocumentor/phpdocumentor":"2.*",
22+
"phpunit/phpunit": ">=7.0",
2423
"phpmd/phpmd": "2.*",
2524
"phpstan/phpstan": "^0.12.88"
2625
},

phpunit.xml.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
</whitelist>
1919
</filter>
2020
<logging>
21-
<log type="coverage-html" target="./build/coverage" />
22-
<log type="coverage-clover" target="./build/logs/clover.xml" />
21+
<log type="coverage-clover" target="./build/clover.xml" />
2322
</logging>
2423
</phpunit>

src/Common/XMLReader.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use DOMDocument;
2121
use DOMElement;
22-
use DOMNode;
2322
use DOMNodeList;
2423
use DOMXpath;
2524
use ZipArchive;
@@ -55,7 +54,7 @@ class XMLReader
5554
*
5655
* @throws \Exception
5756
*/
58-
public function getDomFromZip($zipFile, $xmlFile)
57+
public function getDomFromZip(string $zipFile, string $xmlFile)
5958
{
6059
if (file_exists($zipFile) === false) {
6160
throw new \Exception('Cannot find archive file.');
@@ -80,7 +79,7 @@ public function getDomFromZip($zipFile, $xmlFile)
8079
*
8180
* @return DOMDocument
8281
*/
83-
public function getDomFromString($content)
82+
public function getDomFromString(string $content)
8483
{
8584
$originalLibXMLEntityValue = libxml_disable_entity_loader(true);
8685
$this->dom = new DOMDocument();
@@ -101,7 +100,7 @@ public function getDomFromString($content)
101100
public function getElements(string $path, DOMElement $contextNode = null)
102101
{
103102
if ($this->dom === null) {
104-
return new DOMNodeList;
103+
return new DOMNodeList();
105104
}
106105
if ($this->xpath === null) {
107106
$this->xpath = new DOMXpath($this->dom);

tests/Common/Tests/DrawingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testHTML(): void
104104
$this->assertNull(Drawing::htmlToRGB('0000'));
105105
$this->assertNull(Drawing::htmlToRGB('00000'));
106106

107-
$this->assertInternalType('array', Drawing::htmlToRGB('ABCDEF'));
107+
$this->assertIsArray(Drawing::htmlToRGB('ABCDEF'));
108108
$this->assertCount(3, Drawing::htmlToRGB('ABCDEF'));
109109
$this->assertEquals([0xAB, 0xCD, 0xEF], Drawing::htmlToRGB('ABCDEF'));
110110
$this->assertEquals([0xAB, 0xCD, 0xEF], Drawing::htmlToRGB('#ABCDEF'));

tests/Common/Tests/FileTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function testFileExists(): void
3939
public function testGetFileContents(): void
4040
{
4141
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR;
42-
$this->assertInternalType('string', File::fileGetContents($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo.png'));
42+
$this->assertIsString(File::fileGetContents($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo.png'));
4343
$this->assertNull(File::fileGetContents($pathResources . 'images' . DIRECTORY_SEPARATOR . 'PHPPowerPointLogo_404.png'));
44-
$this->assertInternalType('string', File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#[Content_Types].xml'));
44+
$this->assertIsString(File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#[Content_Types].xml'));
4545
$this->assertNull(File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . 'Sample_01_Simple.pptx#404.xml'));
4646
$this->assertNull(File::fileGetContents('zip://' . $pathResources . 'files' . DIRECTORY_SEPARATOR . '404.pptx#404.xml'));
4747
}

tests/Common/Tests/XMLReaderTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
namespace PhpOffice\Common\Tests;
1919

20+
use Exception;
21+
use InvalidArgumentException;
2022
use PhpOffice\Common\XMLReader;
23+
use PHPUnit\Framework\TestCase;
2124

2225
/**
2326
* Test class for XMLReader
2427
*
2528
* @coversDefaultClass \PhpOffice\Common\XMLReader
2629
*/
27-
class XMLReaderTest extends \PHPUnit\Framework\TestCase
30+
class XMLReaderTest extends TestCase
2831
{
2932
/**
3033
* Test reading XML from string
@@ -58,11 +61,12 @@ public function testDomFromZip(): void
5861

5962
/**
6063
* Test that read from non existing archive throws exception
61-
*
62-
* @expectedException \Exception
6364
*/
6465
public function testThrowsExceptionOnNonExistingArchive(): void
6566
{
67+
$this->expectException(Exception::class);
68+
$this->expectExceptionMessage('Cannot find archive file.');
69+
6670
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
6771

6872
$reader = new XMLReader();
@@ -86,7 +90,7 @@ public function testCountElements(): void
8690
public function testReturnNullOnNonExistingNode(): void
8791
{
8892
$reader = new XMLReader();
89-
$this->assertEmpty($reader->getElements('/element/children'));
93+
$this->assertCount(0, $reader->getElements('/element/children'));
9094
$reader->getDomFromString('<element><child>AAA</child></element>');
9195

9296
$this->assertNull($reader->getElement('/element/children'));
@@ -125,11 +129,12 @@ public function testShouldParseXmlWithCustomNamespace(): void
125129

126130
/**
127131
* Test that xpath fails if custom namespace is not registered
128-
*
129-
* @expectedException \InvalidArgumentException
130132
*/
131133
public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc(): void
132134
{
135+
$this->expectException(InvalidArgumentException::class);
136+
$this->expectExceptionMessage('Dom needs to be loaded before registering a namespace');
137+
133138
$reader = new XMLReader();
134139
$reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
135140
}

tests/Common/Tests/XMLWriterTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ public function testWriteAttributeShouldWriteFloatValueLocaleIndependent(): void
6262
$xmlWriter->writeAttribute('name', $value);
6363
$xmlWriter->endElement();
6464

65+
// https://www.php.net/manual/en/language.types.string.php#language.types.string.casting
66+
// As of PHP 8.0.0, the decimal point character is always ..
67+
// Prior to PHP 8.0.0, the decimal point character is defined in the script's locale (category LC_NUMERIC).
6568
setlocale(LC_NUMERIC, 'de_DE.UTF-8', 'de');
66-
67-
$this->assertSame('1,2', (string) $value);
69+
if (PHP_VERSION_ID > 80000) {
70+
$this->assertSame('1.2', (string) $value);
71+
} else {
72+
$this->assertSame('1,2', (string) $value);
73+
}
6874
$this->assertSame('<element name="1.2"/>' . chr(10), $xmlWriter->getData());
6975
}
7076
}

tests/Common/Tests/_includes/XmlDocument.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ public function getPath(): string
155155
*
156156
* @return string
157157
*/
158-
public function getElementAttribute(string $path, string $attribute, string $file = 'word/document.xml'): string
158+
public function getElementAttribute(string $path, string $attribute, string $file = 'word/document.xml'): string
159159
{
160160
$element = $this->getElement($path, $file);
161+
161162
return $element instanceof DOMElement ? $element->getAttribute($attribute) : '';
162163
}
163164

@@ -173,6 +174,7 @@ public function getElementAttribute(string $path, string $attribute, string $fil
173174
public function attributeElementExists(string $path, string $attribute, string $file = 'word/document.xml'): bool
174175
{
175176
$element = $this->getElement($path, $file);
177+
176178
return $element instanceof DOMElement ? $element->hasAttribute($attribute) : false;
177179
}
178180

0 commit comments

Comments
 (0)