Skip to content

Commit

Permalink
Upgrade to PHPUnit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Feb 19, 2020
1 parent 789406e commit f75c1dd
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/composer.lock
/.phpunit.result.cache
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=7.2.0"
},
"suggest": {
"symfony/css-selector": "Provides facilities is you prefers CSS to Xpath"
},
"autoload": {
"psr-0": { "Welldom": "src/" }
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0"
}
}
8 changes: 6 additions & 2 deletions tests/Welldom/Tests/DocumentFragmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;

/**
* @covers \Welldom\DocumentFragment
*/
class DocumentFragmentTest extends TestCase
{
use TestHelpers;

public function testAppendXmlError()
{
$doc = $this->createDocument('<foo />');
$fragment = $doc->createDocumentFragment();

$errors = $fragment->getLastErrors();
$this->assertInternalType('array', $errors);
$this->assertIsArray($errors);
$this->assertCount(0, $errors);

$success = $fragment->appendXML('<invalid att="v><test></invalid>');
$this->assertSame(false, $success);

$errors = $fragment->getLastErrors();
$this->assertInternalType('array', $errors);
$this->assertIsArray($errors);
$this->assertCount(5, $errors);
}

Expand Down
7 changes: 5 additions & 2 deletions tests/Welldom/Tests/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;
use Welldom\Document;

/**
* @covers \Welldom\Document
*/
class DocumentTest extends TestCase
{
use TestHelpers;

public function testConstructorEncoding()
{
$doc = Document::create('<foo />', 'UTF-8');
Expand Down Expand Up @@ -81,11 +84,11 @@ public function testLoadXMLError()
$this->assertEquals(array(), $doc->getLastErrors());

$this->assertFalse($doc->loadXML(''), '->loadXML() returns false with empty string');
$this->assertInternalType('array', $doc->getLastErrors());
$this->assertIsArray($doc->getLastErrors());
$this->assertCount(1, $doc->getLastErrors());

$this->assertFalse($doc->loadXML('<foo><bar></foo a="1>'), '->loadXML() returns false with invalid XML');
$this->assertInternalType('array', $doc->getLastErrors());
$this->assertIsArray($doc->getLastErrors());
$this->assertCount(3, $doc->getLastErrors());
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Welldom/Tests/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;

/**
* @covers \Welldom\Element
*/
class ElementTests extends TestCase
{
use TestHelpers;

// ->getDocument()

public function testGetDocument()
Expand Down
3 changes: 3 additions & 0 deletions tests/Welldom/Tests/NodeListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;

class NodeListTest extends TestCase
{
use TestHelpers;

// ->getIterator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Welldom\Document;

class TestCase extends \PHPUnit_Framework_TestCase
trait TestHelpers
{
/**
* @param string $source XML source
Expand Down
3 changes: 3 additions & 0 deletions tests/Welldom/Tests/XmlSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;
use Welldom\XmlSerializer;

/**
* @covers \Welldom\XmlSerializer
*/
class XmlSerializerTest extends TestCase
{
use TestHelpers;

/**
* @dataProvider dataForTestXmlToArrayToXml
*/
Expand Down
9 changes: 6 additions & 3 deletions tests/Welldom/Tests/XpathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;
use Welldom\Exception\InvalidXpathException;
use Welldom\Xpath;

/**
* @covers \Welldom\Xpath
*/
class XpathTest extends TestCase
{
use TestHelpers;

/**
* @covers Welldom\Xpath::queryOne
Expand All @@ -32,10 +35,10 @@ public function testQueryOne()

/**
* @covers Welldom\Xpath::queryOne
* @expectedException \Welldom\Exception\InvalidXpathException
*/
public function testQueryOneException()
{
$this->expectException(InvalidXpathException::class);
$this->getXpath('<foo/>')->queryOne('foo[');
}

Expand All @@ -52,10 +55,10 @@ public function testQuery()

/**
* @covers Welldom\Xpath::query
* @expectedException \Welldom\Exception\InvalidXpathException
*/
public function testQueryException()
{
$this->expectException(InvalidXpathException::class);
$this->getXpath('<foo/>')->query('foo[');
}

Expand All @@ -71,10 +74,10 @@ public function testEvaluate()

/**
* @covers Welldom\Xpath::evaluate
* @expectedException \Welldom\Exception\InvalidXpathException
*/
public function testEvaluateException()
{
$this->expectException(InvalidXpathException::class);
$this->getXpath('<foo/>')->evaluate('foo[');
}

Expand Down
11 changes: 5 additions & 6 deletions tests/Welldom/Tests/XsltProcessorCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;
use Welldom\XsltProcessorCollection;

/**
* @covers \Welldom\XsltProcessorCollection
*/
class XsltProcessorCollectionTest extends TestCase
{
use TestHelpers;

public function testGetXsltProcessor()
{
$filename = FILES_DIR . '/frameworks.xsl';
Expand All @@ -27,19 +30,15 @@ public function testGetXsltProcessor()
XsltProcessorCollection::free();
}

/**
* @expectedException \DOMException
*/
public function testGetXsltProcessorLoadException()
{
$this->expectException(\DOMException::class);
XsltProcessorCollection::getXsltProcessor(FILES_DIR . '/frameworks-invalid.xsl');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testGetXsltProcessorFileException()
{
$this->expectException(\InvalidArgumentException::class);
XsltProcessorCollection::getXsltProcessor(FILES_DIR . '/does-not-exists.xsl');
}
}
4 changes: 3 additions & 1 deletion tests/Welldom/Tests/XsltProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Welldom\Tests;

use PHPUnit\Framework\TestCase;
use Welldom\XsltProcessor;
use Welldom\Document;

Expand All @@ -19,6 +20,7 @@
*/
class XsltProcessorTest extends TestCase
{
use TestHelpers;

// ->__construct()

Expand All @@ -29,7 +31,7 @@ public function testConstructor($filename, $errorsCount)
{
$xslt = new XsltProcessor(FILES_DIR . $filename);

$this->assertInternalType('array', $xslt->getLastErrors());
$this->assertIsArray($xslt->getLastErrors());
$this->assertCount($errorsCount, $xslt->getLastErrors());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
*/

require_once __DIR__ . '/../src/autoload.php';
require_once __DIR__ . '/Welldom/Tests/TestCase.php';
require_once __DIR__ . '/Welldom/Tests/TestHelpers.php';
define('FILES_DIR', realpath(__DIR__ . '/_files'));

0 comments on commit f75c1dd

Please sign in to comment.