142 lines
3.3 KiB
PHP
142 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace SMW\Tests;
|
|
|
|
use SMW\ConstraintFactory;
|
|
use SMW\Tests\Fixtures\PlainClass;
|
|
|
|
/**
|
|
* @covers \SMW\ConstraintFactory
|
|
* @group semantic-mediawiki
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
* @since 3.1
|
|
*
|
|
* @author mwjames
|
|
*/
|
|
class ConstraintFactoryTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
use PHPUnitCompat;
|
|
|
|
public function testCanConstruct() {
|
|
$this->assertInstanceOf(
|
|
ConstraintFactory::class,
|
|
new ConstraintFactory()
|
|
);
|
|
}
|
|
|
|
public function testCanConstructConstraintRegistry() {
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->assertInstanceOf(
|
|
'\SMW\Constraint\ConstraintRegistry',
|
|
$instance->newConstraintRegistry()
|
|
);
|
|
}
|
|
|
|
public function testCanConstructConstraintCheckRunner() {
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->assertInstanceOf(
|
|
'\SMW\Constraint\ConstraintCheckRunner',
|
|
$instance->newConstraintCheckRunner()
|
|
);
|
|
}
|
|
|
|
public function testCanConstructNullConstraint() {
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->assertInstanceOf(
|
|
'\SMW\Constraint\Constraints\NullConstraint',
|
|
$instance->newNullConstraint()
|
|
);
|
|
}
|
|
|
|
public function testCanConstructConstraintSchemaCompiler() {
|
|
$store = $this->getMockBuilder( '\SMW\Store' )
|
|
->disableOriginalConstructor()
|
|
->getMockForAbstractClass();
|
|
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->assertInstanceOf(
|
|
'\SMW\Constraint\ConstraintSchemaCompiler',
|
|
$instance->newConstraintSchemaCompiler( $store )
|
|
);
|
|
}
|
|
|
|
public function testNewConstraintByClassInvalidClassThrowsException() {
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->expectException( '\SMW\Exception\ClassNotFoundException' );
|
|
$instance->newConstraintByClass( 'ThisIsNotAClass' );
|
|
}
|
|
|
|
public function testNewConstraintByClassNonConstraintClassThrowsException() {
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->expectException( '\RuntimeException' );
|
|
$instance->newConstraintByClass( PlainClass::class );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider constraintByClassProvider
|
|
*/
|
|
public function testCanConstructConstraintByClass( $class, $expected ) {
|
|
$instance = new ConstraintFactory();
|
|
|
|
$this->assertInstanceOf(
|
|
'\SMW\Constraint\Constraint',
|
|
$instance->newConstraintByClass( $class )
|
|
);
|
|
|
|
$this->assertInstanceOf(
|
|
$expected,
|
|
$instance->newConstraintByClass( $class )
|
|
);
|
|
}
|
|
|
|
public function constraintByClassProvider() {
|
|
yield [
|
|
'\SMW\Constraint\Constraints\NullConstraint',
|
|
'\SMW\Constraint\Constraints\NullConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\NamespaceConstraint',
|
|
'\SMW\Constraint\Constraints\NamespaceConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\UniqueValueConstraint',
|
|
'\SMW\Constraint\Constraints\UniqueValueConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\NonNegativeIntegerConstraint',
|
|
'\SMW\Constraint\Constraints\NonNegativeIntegerConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\SingleValueConstraint',
|
|
'\SMW\Constraint\Constraints\SingleValueConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\MustExistsConstraint',
|
|
'\SMW\Constraint\Constraints\MustExistsConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\MandatoryPropertiesConstraint',
|
|
'\SMW\Constraint\Constraints\MandatoryPropertiesConstraint'
|
|
];
|
|
|
|
yield [
|
|
'SMW\Constraint\Constraints\ShapeConstraint',
|
|
'\SMW\Constraint\Constraints\ShapeConstraint'
|
|
];
|
|
}
|
|
|
|
}
|