Skip to content

Commit 50b5432

Browse files
committed
Added negative assertion
1 parent 758a948 commit 50b5432

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Cmf/Component/Testing/Unit/XmlSchemaTestCase.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
class XmlSchemaTestCase extends \PHPUnit_Framework_TestCase
66
{
77
public static function assertSchemaAcceptsXml($xmlDoms, $schemaPath, $message = '')
8+
{
9+
return self::assertThat($schemaPath, self::getSchemaAcceptsXmlConstraint($xmlDoms), $message);
10+
}
11+
12+
public static function assertSchemaRefusesXml($xmlDoms, $schemaPath, $message = '')
13+
{
14+
return self::assertThat(
15+
$schemaPath,
16+
new \PHPUnit_Framework_Constraint_Not(self::getSchemaAcceptsXmlConstraint($xmlDoms)),
17+
$message
18+
);
19+
}
20+
21+
private static function getSchemaAcceptsXmlConstraint($xmlDoms)
822
{
923
if (!is_array($xmlDoms)) {
1024
$xmlDoms = array($xmlDoms);
@@ -26,6 +40,6 @@ public static function assertSchemaAcceptsXml($xmlDoms, $schemaPath, $message =
2640
return $dom;
2741
}, $xmlDoms);
2842

29-
return self::assertThat($schemaPath, new Constraint\SchemaAcceptsXml($xmlDoms), $message);
43+
return new Constraint\SchemaAcceptsXml($xmlDoms);
3044
}
3145
}

tests/Unit/XmlSchemaTestCaseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ public function testAcceptsSingleDomsWithoutArray()
1212
$dom->loadXML('<container><config xmlns="http://cmf.symfony.com/schema/dic/foo" required="f"/></container>');
1313
$this->assertSchemaAcceptsXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd');
1414
}
15+
16+
public function testNegativeAssertion()
17+
{
18+
$dom = new \DomDocument();
19+
$dom->loadXML('<container><config xmlns="http://cmf.symfony.com/schema/dic/foo" /></container>');
20+
21+
$this->assertSchemaRefusesXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd');
22+
}
1523
}

0 commit comments

Comments
 (0)