Download the PHP package sweetrdf/rdf-interface-tests without Composer
On this page you can find all versions of the php package sweetrdf/rdf-interface-tests. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sweetrdf/rdf-interface-tests
More information about sweetrdf/rdf-interface-tests
Files in sweetrdf/rdf-interface-tests
Package rdf-interface-tests
Short Description Test checking rdfInterface compliance
License MIT
Homepage https://github.com/sweetrdf/rdfInterfaceTests
Informations about the package rdf-interface-tests
RdfInterface compliance tests
A set of PHPUnit tests for checking compliance of your classes with the rdfInterface.
Usage
I assume you are using the composer to manage your code dependencies.\ If not, it's definitely a good idea to start using it.
-
Declare
sweetrdf/rdf-interface-tests
as development dependency of your package - Prepare your own test classes inheriting from classes provided by this package.
- Available test classes are in the src/rdfInterface/tests directory of this repository.
- A sample implementation is provided below.
- You are free to extend your classes with additional tests.
- Run PHPUnit
Sample implementation
Let's assume I developed a myOwnRdf\MyOwnNamedNode
class implementing the rdfInterface\NamedNode
interface.
The class providing compliance tests for the rdfInterface\NamedNode
is \rdfInterface\tests\TermsTest
. See here.
The \rdfInterface\tests\TermsTest
class declares two abstract methods (trough the TestBaseTrait) which I have to implement:
abstract public static function getDataFactory(): \rdfInterface\DataFactory
This one's pretty obvious. The test class has to know what should be tested and I must implement a method which will give it access to my implementation of therdfInterface\NamedNode
interface. As in the rdfInterface terms (named/blank nodes, literals, quads, default graphs) are expected to be created by a static factory class implementing therdfInterface\DataFactory
I must provide a method returning instance of such a class (by the way yes, it means that if a given term can be created by therdfInterface\DataFactory
, you can't implement it alone but must provide also ardfInterface\DataFactory
implementation; at least when you want it to be testable). So let's assume here I also developedmyOwnRdf\MyOwnDataFactory
implementing therdfInterface\DataFactory
.abstract public static function getForeignDataFactory(): DataFactory
This one is not so obvious. The important thing about using a common iterface is to assure different implementations can work with each other (are interoperable), e.g. thatmyOwnRdf\MyOwnNamedNode::equals(rdfInterface\Term $term)
returns correct results not only with$term
beingmyOwnRdf\MyOwnNamedNode
but coming from any other implementation. To check that the test class must be able to generate terms coming from another implementation. As we already know terms are to be generated trough a rdfInterface\DataFactory` implementation. This method is supposed to return such a "foreign terms factory".- If I don't want to perform interoperability tests, I can just implement this method as returning my implementation of the
rdfInterface\DataFactory
(heremyOwnRdf\MyOwnDataFactory
). - I decided to use
simpleRdf\DataFactory
from the simpleRdf (all in all it's meant exactly for that).
- If I don't want to perform interoperability tests, I can just implement this method as returning my implementation of the
Knowing all of that I can prepare my own test class inheriting from \rdfInterface\tests\TermsTest
. Just:
- My own test class name must end with
Test
so the PHPUnit recognizes it properly. Let's make itmyOwnRdf\MyOwnNamedNodeTest
. \rdfInterface\tests\TermsTest
contains a lot of tests for other kind of terms. I must mask them (see code sample below).- I will also add my own test checking some unique features of my implementation.
You can find more exhaustive examples of reusing tests provided by this package in simpleRdf library tests and quickRdf library tests.
All versions of rdf-interface-tests with dependencies
zozlak/rdf-constants Version ^1.1
sweetrdf/rdf-interface Version ^2
sweetrdf/rdf-helpers Version ^2
phpunit/phpunit Version ^10