Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlovl committed May 1, 2015
1 parent 96f3934 commit 392362e
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- hhvm-nightly

# run build against hhvm but allow them to fail
# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail
matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: hhvm-nightly
- php: 7.0

# faster builds on new travis setup not using sudo
sudo: false

# cache vendor dirs
cache:
directories:
- vendor
- $HOME/.composer/cache

install:
- travis_retry composer self-update && composer --version
- travis_retry composer global require "fxp/composer-asset-plugin:1.0.0"
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer install --prefer-dist --no-interaction

before_script:
- mysql -e 'CREATE DATABASE yiitest;';

script:
- phpunit --verbose $PHPUNIT_FLAGS

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"require": {
"yiisoft/yii2": "~2.0"
},
"require-dev": {
"yiisoft/yii2-dev": "~2.0"
},
"autoload": {
"psr-4": { "lvl\\staticactiverecord\\": "" }
}
Expand Down
13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="staticactiverecord">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
12 changes: 12 additions & 0 deletions tests/ActiveRecordTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace lvl\staticactiverecord\unit;

class ActiveRecordTest extends \yiiunit\framework\db\ActiveRecordTest
{
protected function setUp()
{
static::$params = require(__DIR__ . '/data/config.php');
parent::setUp();
}
}
15 changes: 15 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
// ensure we get report on all possible php errors
error_reporting(-1);

define('YII_ENABLE_ERROR_HANDLER', false);
define('YII_DEBUG', true);
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
$_SERVER['SCRIPT_FILENAME'] = __FILE__;

require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

Yii::setAlias('@yiiunit', __DIR__ . '/../vendor/yiisoft/yii2-dev/tests/unit');

Yii::$classMap['yiiunit\data\ar\ActiveRecord'] = __DIR__ . '/override/ActiveRecord.php';
1 change: 1 addition & 0 deletions tests/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.local.php
16 changes: 16 additions & 0 deletions tests/data/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
$config = [
'databases' => [
'mysql' => [
'dsn' => 'mysql:host=127.0.0.1;dbname=yiitest',
'username' => 'travis',
'password' => '',
'fixture' => __DIR__ . '/../../vendor/yiisoft/yii2-dev/tests/unit/data/mysql.sql',
]
],
];

if (is_file(__DIR__ . '/config.local.php')) {
include(__DIR__ . '/config.local.php');
}
return $config;
20 changes: 20 additions & 0 deletions tests/override/ActiveRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace yiiunit\data\ar;

/**
* This class, combined with the classloader override in bootstrap.php, makes all instances
* of yiiunit\data\ar\ActiveRecord extend from this extension's ActiveRecord version instead
* of the original yii\db\ActiveRecord.
*
* This allows us to run the entire Yii ActiveRecord testsuite without overriding each AR class.
*/
class ActiveRecord extends \lvl\staticactiverecord\db\ActiveRecord
{
public static $db;

public static function getDb()
{
return self::$db;
}
}

0 comments on commit 392362e

Please sign in to comment.