Skip to content

Commit

Permalink
Merge pull request #38 from Wikidata-lib/travis_config_merged
Browse files Browse the repository at this point in the history
Travis config
  • Loading branch information
xchrdw committed Mar 12, 2014
2 parents 1596e62 + 0cd8b66 commit e78d4c1
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 19 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
@@ -0,0 +1,13 @@
language: php

env:
- DBTYPE=mysql
- DBTYPE=sqlite
php:
- 5.3

before_script:
- bash ./build/travis/before_script.sh

script:
- bash ./build/travis/script.sh
12 changes: 11 additions & 1 deletion PropertySuggesterHooks.php
Expand Up @@ -23,8 +23,18 @@ public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
* @return bool
*/
public static function onUnitTestsList( &$files ) {
$files = array_merge( $files, glob( __DIR__ . '/tests/phpunit/*Test.php' ) );
// @codeCoverageIgnoreStart
$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/phpunit/' );
/**
* @var SplFileInfo $fileInfo
*/
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
$files[] = $fileInfo->getPathname();
}
}
return true;
// @codeCoverageIgnoreEnd
}

/**
Expand Down
52 changes: 52 additions & 0 deletions build/travis/before_script.sh
@@ -0,0 +1,52 @@
#! /bin/bash

set -x

originalDirectory=$(pwd)

cd ..

# checkout mediawiki
wget https://github.com/wikimedia/mediawiki-core/archive/master.tar.gz
tar -zxf master.tar.gz
rm master.tar.gz
mv mediawiki-core-master wiki

# checkout wikibase
wget https://github.com/wikimedia/mediawiki-extensions-Wikibase/archive/master.tar.gz
tar -zxf master.tar.gz
rm master.tar.gz
mv mediawiki-extensions-Wikibase-master wiki/extensions/Wikibase

cd wiki

if [ $DBTYPE == "mysql" ]
then
mysql -e 'CREATE DATABASE its_a_mw;'
fi

php maintenance/install.php --dbtype $DBTYPE --dbuser root --dbname its_a_mw --dbpath $(pwd) --pass nyan TravisWiki admin

cd extensions

cp -r $originalDirectory PropertySuggester

cd Wikibase
composer install --prefer-source

cd ../..

echo 'error_reporting(E_ALL| E_STRICT);' >> LocalSettings.php
echo 'ini_set("display_errors", 1);' >> LocalSettings.php
echo '$wgShowExceptionDetails = true;' >> LocalSettings.php
echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php
echo '$wgLanguageCode = "en";' >> LocalSettings.php

echo "define( 'WB_EXPERIMENTAL_FEATURES', true );" >> LocalSettings.php
echo 'require_once __DIR__ . "/extensions/Wikibase/repo/Wikibase.php";' >> LocalSettings.php
echo 'require_once __DIR__ . "/extensions/Wikibase/repo/ExampleSettings.php";' >> LocalSettings.php
echo 'require_once __DIR__ . "/extensions/Wikibase/client/WikibaseClient.php";' >> LocalSettings.php
echo 'require_once __DIR__ . "/extensions/PropertySuggester/PropertySuggester.php";' >> LocalSettings.php
echo '$wgWBClientSettings["siteGlobalID"] = "enwiki";' >> LocalSettings.php

php maintenance/update.php --quick
7 changes: 7 additions & 0 deletions build/travis/script.sh
@@ -0,0 +1,7 @@
#! /bin/bash

set -x

cd ../wiki/tests/phpunit

php phpunit.php --debug --group PropertySuggester
13 changes: 7 additions & 6 deletions sql/create_propertypairs.sql
@@ -1,8 +1,9 @@

CREATE TABLE wbs_propertyPairs(
pid1 INT,
pid2 INT,
count INT,
probability FLOAT,
CREATE TABLE IF NOT EXISTS /*_*/wbs_propertypairs(
pid1 INT unsigned NOT NULL,
pid2 INT unsigned NOT NULL,
count INT unsigned NOT NULL,
probability FLOAT NOT NULL,
PRIMARY KEY(pid1, pid2)
);
) /*$wgDBTableOptions*/;

1 change: 0 additions & 1 deletion src/PropertySuggester/GetSuggestions.php
Expand Up @@ -12,7 +12,6 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\EntityLookup;
use Wikibase\Repo\WikibaseRepo;
use Wikibase\StoreFactory;
use Wikibase\Utils;
Expand Down
6 changes: 5 additions & 1 deletion src/PropertySuggester/Suggesters/SimplePHPSuggester.php
Expand Up @@ -14,7 +14,11 @@
* Needs the wbs_propertypairs table filled with pair probabilities.
*/
class SimplePHPSuggester implements SuggesterEngine {
private $deprecatedPropertyIds = [ 107 ];

/**
* @var int[]
*/
private $deprecatedPropertyIds = array( 107 );

/**
* @param DatabaseBase $dbr
Expand Down
Expand Up @@ -14,7 +14,7 @@
*
* @covers PropertySuggester\Suggesters\SimplePHPSuggester
*
* @group Extensions/PropertySuggester
* @group PropertySuggester
*
* @group API
* @group Database
Expand Down Expand Up @@ -42,25 +42,27 @@ public function addDBData() {
$rows[] = $this->row( 2, 4, 200, 0.2 );
$rows[] = $this->row( 3, 1, 100, 0.5 );

$this->db->delete( 'wbs_propertypairs', "*" );
$this->db->insert( 'wbs_propertypairs', $rows );
}

public function setUp() {
parent::setUp();
$this->suggester = new SimplePHPSuggester( $this->db );

$this->tablesUsed[] = 'wbs_propertypairs';

$this->suggester = new SimplePHPSuggester( $this->db );
}

public function testDatabaseHasRows() {
$res = $this->db->select( 'wbs_propertypairs', array( 'pid1', 'pid2') );
$res = $this->db->select( 'wbs_propertypairs', array( 'pid1', 'pid2' ) );
$this->assertEquals( 5, $res->numRows() );
}


public function testSuggestByPropertyIds() {
$ids = array( PropertyId::newFromNumber( 1 ) );

$res = $this->suggester->suggestByPropertyIds($ids);
$res = $this->suggester->suggestByPropertyIds( $ids );

$this->assertEquals( PropertyId::newFromNumber( 2 ), $res[0]->getPropertyId() );
$this->assertEquals( PropertyId::newFromNumber( 3 ), $res[1]->getPropertyId() );
Expand All @@ -72,7 +74,7 @@ public function testSuggestByItem() {
$statement->setGuid( 'claim0' );
$item->addClaim( $statement );

$res = $this->suggester->suggestByItem($item);
$res = $this->suggester->suggestByItem( $item );

$this->assertEquals( PropertyId::newFromNumber( 2 ), $res[0]->getPropertyId() );
$this->assertEquals( PropertyId::newFromNumber( 3 ), $res[1]->getPropertyId() );
Expand All @@ -85,10 +87,9 @@ public function testDeprecatedProperties() {

$res = $this->suggester->suggestByPropertyIds( $ids );

$resIds = array_map( function( $r ) { return $r->getPropertyId()->getSerialization(); }, $res );
$this->assertNotContains( "P2", $resIds );
$this->assertContains( "P3", $resIds );

$resultIds = array_map( function ( Suggestion $r ) { return $r->getPropertyId()->getNumericId(); }, $res );
$this->assertNotContains( 2 , $resultIds );
$this->assertContains( 3 , $resultIds );
}

public function tearDown() {
Expand Down

0 comments on commit e78d4c1

Please sign in to comment.