Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from idimopoulos/ISAICP-5599
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea committed Feb 1, 2021
2 parents 3e51378 + 8ae306f commit e4fec4b
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 10 deletions.
55 changes: 55 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
language: php

php:
- '7.2'
- '7.3'
- '7.4'

sudo: required

services:
- mysql
- docker

mysql:
database: sparql_entity_storage_test
username: root
encoding: utf8

env:
global:
- SITE_DIR="$HOME/build/testing_site"
matrix:
- TEST=PHPCodeSniffer
- TEST=PHPStan DRUPAL=~8.9.0 PHPUNIT=^7
- TEST=PHPUnit DRUPAL=~8.9.0 PHPUNIT=^7
- TEST=PHPUnit DRUPAL=~9.0.0 PHPUNIT=^8
- TEST=PHPUnit DRUPAL=~9.1.0 PHPUNIT=^8
- TEST=PHPUnit DRUPAL=~9.2.0 PHPUNIT=^8

matrix:
fast_finish: true
exclude:
- php: '7.2'
env: TEST=PHPUnit DRUPAL=~9.0.0 PHPUNIT=^8
- php: '7.2'
env: TEST=PHPUnit DRUPAL=~9.1.0 PHPUNIT=^8
- php: '7.2'
env: TEST=PHPUnit DRUPAL=~9.2.0 PHPUNIT=^8
- php: '7.3'
env: TEST=PHPCodeSniffer
- php: '7.3'
env: TEST=PHPStan DRUPAL=~8.9.0 PHPUNIT=^7
- php: '7.4'
env: TEST=PHPCodeSniffer
- php: '7.4'
env: TEST=PHPStan DRUPAL=~8.9.0 PHPUNIT=^7

before_install:
# Remove this line to run with Xdebug enabled.
- phpenv config-rm xdebug.ini || true

script: ${TRAVIS_BUILD_DIR}/tests/travis-ci/scripts/run_tests.sh

notifications:
email: false
20 changes: 19 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@
"source": "https://cgit.drupalcode.org/sparql_entity_storage"
},
"license": "GPL-2.0+",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"easyrdf/easyrdf": "1.0.0 as 0.9.2",
"ml/json-ld": "^1.0"
},
"require-dev": {
"minimaxir/big-list-of-naughty-strings": "dev-master"
"minimaxir/big-list-of-naughty-strings": "dev-master",
"drupal/coder": "^8.3",
"mglaman/phpstan-drupal": "^0.12.6",
"phpstan/phpstan-deprecation-rules": "^0.12.5"
},
"repositories": [
{
"type": "package",
"package": {
"name": "minimaxir/big-list-of-naughty-strings",
"version": "dev-master",
"dist": {
"url": "https://github.com/minimaxir/big-list-of-naughty-strings/archive/master.zip",
"type": "zip"
}
}
}
],
"autoload": {
"classmap": [
"src/Driver/Database/sparql/Connection.php"
Expand Down
27 changes: 27 additions & 0 deletions phpcs-ruleset.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!-- PHP_CodeSniffer standard for Drupal modules. -->
<!-- See http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
<ruleset name="Drupal Module">
<description>Drupal coding standard for contributed modules</description>

<!-- Exclude unsupported file types. -->
<exclude-pattern>*.gif</exclude-pattern>
<exclude-pattern>*.less</exclude-pattern>
<exclude-pattern>*.png</exclude-pattern>

<!-- Minified files don't have to comply with coding standards. -->
<exclude-pattern>*.min.css</exclude-pattern>
<exclude-pattern>*.min.js</exclude-pattern>

<rule ref="./vendor/drupal/coder/coder_sniffer/Drupal">
<!-- URLs in deprecation messages point to Github rather than drupal.org. -->
<exclude name="Drupal.Semantics.FunctionTriggerError.TriggerErrorSeeUrlFormat" />
<!-- Deprecation versions are allowed to include beta versions. -->
<exclude name="Drupal.Semantics.FunctionTriggerError.TriggerErrorVersion" />
</rule>
<rule ref="./vendor/drupal/coder/coder_sniffer/DrupalPractice">
<exclude name="DrupalPractice.Objects.GlobalFunction.GlobalFunction" />
<exclude name="DrupalPractice.Objects.GlobalDrupal.GlobalDrupal" />
<exclude name="DrupalPractice.InfoFiles.NamespacedDependency.NonNamespaced" />
</rule>
</ruleset>
10 changes: 10 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="pbm_default">
<description>Default PHP CodeSniffer configuration for SPARQL Entity Storage.</description>
<rule ref="phpcs-ruleset.xml.dist"/>
<arg name="extensions" value="php,inc,module,install,info,test,profile,theme,css,js"/>
<arg name="report" value="full"/>
<arg value="p"/>
<file>.</file>
<exclude-pattern>./vendor</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion src/Entity/Query/Sparql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected function compile(): SparqlQueryInterface {
// Remap the entity reference default tag to the SPARQL entity reference
// because the first one requires that the query is an instance of the
// SelectInterface.
// @todo: Maybe overwrite the default selection class?
// @todo Maybe overwrite the default selection class?
if (isset($this->alterTags['entity_reference'])) {
$this->alterTags['sparql_reference'] = $this->alterTags['entity_reference'];
unset($this->alterTags['entity_reference']);
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/Query/Sparql/SparqlCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function __construct($conjunction, SparqlQueryInterface $query, array $na
/**
* {@inheritdoc}
*
* @todo: handle the lang.
* @todo handle the lang.
*/
public function condition($field = NULL, $value = NULL, $operator = NULL, $lang = NULL): self {
if ($this->conjunction == 'OR') {
Expand Down Expand Up @@ -296,7 +296,7 @@ public function condition($field = NULL, $value = NULL, $operator = NULL, $lang
* Thrown if the value is NULL or the operator is not allowed.
*/
protected function keyCondition(string $field, $value, string $operator): self {
// @todo: Add support for loadMultiple with empty Id (load all).
// @todo Add support for loadMultiple with empty Id (load all).
if ($value == NULL) {
throw new \Exception('The value cannot be NULL for conditions related to the Id and bundle keys.');
}
Expand Down Expand Up @@ -569,7 +569,7 @@ protected function addDefaultTriplePattern(): void {
* @param array $condition
* The query condition.
*
* @todo: This could work generically but currently the term storage has
* @todo This could work generically but currently the term storage has
* two possible predicates. This can be removed when we will be left with one
* predicate for the term storage.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/SparqlEntityStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected function loadFromStorage(array $ids, array $graph_ids): ?array {
return [];
}

// @todo: We should filter per entity per graph and not load the whole
// @todo We should filter per entity per graph and not load the whole
// database only to filter later on.
// @see https://github.com/ec-europa/sparql_entity_storage/issues/2
$ids_string = SparqlArg::serializeUris($ids, ' ');
Expand Down Expand Up @@ -1084,7 +1084,7 @@ public function hasData() {
* @param array $values
* The field values.
*
* @todo: To be removed when columns will be supported. No need to manually
* @todo To be removed when columns will be supported. No need to manually
* set this.
*/
protected function applyFieldDefaults($type, array &$values): void {
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/SparqlEntityInsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public static function providerTestEntityInsertCallback(): array {
* @return mixed
* The retrieved value or NULL if no value exists.
*
* @todo: Remove this when the deltas are supported.
* @todo: Discuss whether we need this in the storage level.
* @todo Remove this when the deltas are supported.
* @todo Discuss whether we need this in the storage level.
*/
protected function getEntityValue(ContentEntityInterface $entity, string $field_name) {
$value = $entity->get($field_name)->getValue();
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/SparqlGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SparqlGraphTest extends SparqlKernelTestBase {
/**
* Tests graphs.
*/
public function test(): void {
public function testSparqlGraphs(): void {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $manager */
$manager = $this->container->get('entity_type.manager');
/** @var \Drupal\sparql_entity_storage\SparqlEntityStorage $storage */
Expand Down
58 changes: 58 additions & 0 deletions tests/travis-ci/fixtures/composer.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"require": {
"composer/installers": "^1.5.0",
"cweagans/composer-patches": "^1.6.5",
"drupal/core": "${DRUPAL}",
"drupal/core-composer-scaffold": "*",
"drupal/pathauto": "*",
"drupal/sparql_entity_storage": "*",
"drupal/token": "*",
"drush/drush": "~10",
"easyrdf/easyrdf": "1.0.0 as 0.9.2",
"ml/json-ld": "^1.0"
},
"require-dev": {
"behat/mink-goutte-driver": "~1.2",
"mikey179/vfsstream": "~1.2",
"minimaxir/big-list-of-naughty-strings": "dev-master",
"mglaman/phpstan-drupal": "^0.12.6",
"phpspec/prophecy": "^1.7",
"phpstan/phpstan-deprecation-rules": "^0.12.5",
"phpunit/phpunit": "${PHPUNIT}",
"symfony/phpunit-bridge": "^5.1.4"
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "path",
"url": "${TRAVIS_BUILD_DIR}"
},
{
"type": "package",
"package": {
"name": "minimaxir/big-list-of-naughty-strings",
"version": "dev-master",
"dist": {
"url": "https://github.com/minimaxir/big-list-of-naughty-strings/archive/master.zip",
"type": "zip"
}
}
},
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/modules/{$name}": ["type:drupal-module"]
},
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
}
}
}
8 changes: 8 additions & 0 deletions tests/travis-ci/fixtures/connection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

$databases['sparql_default']['default'] = array (
'prefix' => '',
'host' => '127.0.0.1',
'port' => 8890,
'namespace' => 'Drupal\\sparql_entity_storage\\Driver\\Database\\sparql',
'driver' => 'sparql',
);
6 changes: 6 additions & 0 deletions tests/travis-ci/fixtures/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
customRulesetUsed: true
reportUnmatchedIgnoredErrors: false
includes:
- vendor/mglaman/phpstan-drupal/extension.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
27 changes: 27 additions & 0 deletions tests/travis-ci/fixtures/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="web/core/tests/bootstrap.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
>
<php>
<ini name="error_reporting" value="32767"/>
<ini name="memory_limit" value="-1"/>
<env name="SIMPLETEST_BASE_URL" value="http://localhost:8888"/>
<env name="SIMPLETEST_DB" value="mysql://root:@127.0.0.1/sparql_entity_storage_test_phpunit"/>
<env name="SIMPLETEST_SPARQL_DB" value="sparql://127.0.0.1:8890?module=sparql_entity_storage"/>
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/tmp"/>
<env name="BROWSERTEST_OUTPUT_FILE" value="/tmp/browser_output/outputfile.txt"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="99999"/>
</php>
<testsuites>
<testsuite name="sparql_entity_storage">
<directory>./web/modules/sparql_entity_storage</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="\Drupal\Tests\Listeners\DrupalListener"/>
</listeners>
</phpunit>
70 changes: 70 additions & 0 deletions tests/travis-ci/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

install_codebase () {
mkdir -p ${SITE_DIR}/web/modules
cp ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/composer.json.dist ${SITE_DIR}/composer.json
cd ${SITE_DIR}
perl -i -pe's/\$\{([^}]+)\}/$ENV{$1}/' composer.json
COMPOSER_MEMORY_LIMIT=-1 composer install --no-interaction --prefer-dist
}

case "${TEST}" in
PHPCodeSniffer)
cd ${TRAVIS_BUILD_DIR}
composer install
./vendor/bin/phpcs
exit $?
;;
PHPStan)
# Deploy the codebase.
install_codebase
cp ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/phpstan.neon.dist ${SITE_DIR}/phpstan.neon

# Run static analysis.
./vendor/bin/phpstan analyse ./web/modules/sparql_entity_storage
exit $?
;;
PHPUnit)
# Deploy the codebase.
install_codebase

# Setup PHPUnit.
cp ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/phpunit.xml.dist ${SITE_DIR}/phpunit.xml

# Virtuoso setup.
mkdir ${SITE_DIR}/virtuoso
docker run --name virtuoso -p 8890:8890 -p 1111:1111 -e SPARQL_UPDATE=true -v ${SITE_DIR}/virtuoso:/data -d tenforce/virtuoso

# Sleep to ensure that docker services are available.
sleep 15

# Create the MySQL database.
mysql -e 'CREATE DATABASE sparql_entity_storage_test'
mysql -e 'CREATE DATABASE sparql_entity_storage_test_phpunit'

# Install Drupal.
./vendor/bin/drush site:install testing --yes --root=${SITE_DIR}/web --db-url=mysql://root:@127.0.0.1/sparql_entity_storage_test

# Add the SPARQL connection to settings.php.
chmod 0775 ${SITE_DIR}/web/sites/default/settings.php
cat ${TRAVIS_BUILD_DIR}/tests/travis-ci/fixtures/connection.txt >> ${SITE_DIR}/web/sites/default/settings.php

# Enable the 'rdf_entity' module.
./vendor/bin/drush pm:enable sparql_entity_storage --yes --root=${SITE_DIR}/web

# Start the webserver for browser tests.
cd ${SITE_DIR}/web
nohup php -S localhost:8888 > /dev/null 2>&1 &

# Wait until the web server is responding.
until curl -s localhost:8888; do true; done > /dev/null

# Run PHPUnit.
cd ..
./vendor/bin/phpunit --verbose
exit $?
;;
*)
echo "Unknown test '$1'"
exit 1
esac

0 comments on commit e4fec4b

Please sign in to comment.