浏览代码

Fix tests, and make them work with http://travis-ci.org

Thomas Rabaix 13 年之前
父节点
当前提交
81b704afac
共有 5 个文件被更改,包括 64 次插入6 次删除
  1. 4 0
      .travis.yml
  2. 2 2
      Tests/Admin/PoolTest.php
  3. 25 0
      Tests/tests/autoload.php.dist
  4. 5 4
      Tests/tests/bootstrap.php
  5. 28 0
      Tests/tests/vendors.php

+ 4 - 0
.travis.yml

@@ -0,0 +1,4 @@
+language: php
+php: 5.3.8
+before_script: php Tests/tests/vendors.php
+script: phpunit

+ 2 - 2
Tests/Admin/PoolTest.php

@@ -22,7 +22,7 @@ class PoolTest extends \PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        $this->pool = new Pool($this->getContainer());
+        $this->pool = new Pool($this->getContainer(), 'Sonata Admin', '/path/to/pic.png');
     }
 
     public function testGetGroups()
@@ -93,7 +93,7 @@ class PoolTest extends \PHPUnit_Framework_TestCase
             ->method('get')
             ->will($this->returnValue($adminMock));
 
-        $this->pool = new Pool($containerMock);
+        $this->pool = new Pool($containerMock, 'Sonata', '/path/to/logo.png');
 
         $this->assertEquals('commentAdminClass', $this->pool->getAdminByAdminCode('sonata.news.admin.post|sonata.news.admin.comment'));
     }

+ 25 - 0
Tests/tests/autoload.php.dist

@@ -0,0 +1,25 @@
+<?php
+
+$vendorDir = __DIR__.'/../../vendor';
+require_once $vendorDir.'/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
+
+use Symfony\Component\ClassLoader\UniversalClassLoader;
+
+$loader = new UniversalClassLoader();
+$loader->registerNamespaces(array(
+    'Symfony'  => array($vendorDir.'/symfony/src'),
+    'Knp'  => array($vendorDir.'/knpmenu/src'),
+));
+$loader->register();
+
+spl_autoload_register(function($class) {
+    if (0 === strpos($class, 'Sonata\\AdminBundle\\')) {
+        $path = __DIR__.'/../../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
+        
+        if (!stream_resolve_include_path($path)) {
+            return false;
+        }
+        require_once $path;
+        return true;
+    }
+});

+ 5 - 4
Tests/tests/bootstrap.php

@@ -9,7 +9,8 @@
  * file that was distributed with this source code.
  */
 
-$rootDir = __DIR__.'/../../../../../../';
-
-require_once $rootDir.'/vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
-require_once $rootDir.'/app/autoload.php';
+if (file_exists($file = __DIR__.'/autoload.php')) {
+    require_once $file;
+} elseif (file_exists($file = __DIR__.'/autoload.php.dist')) {
+    require_once $file;
+}

+ 28 - 0
Tests/tests/vendors.php

@@ -0,0 +1,28 @@
+#!/usr/bin/env php
+<?php
+
+set_time_limit(0);
+
+
+$vendorDir = __DIR__.'/../../vendor';
+if (!is_dir($vendorDir)) {
+  mkdir($vendorDir);
+}
+
+$deps = array(
+    array('symfony', 'git://github.com/symfony/symfony.git', 'v2.0.5'),
+    array('knpmenu', 'git://github.com/knplabs/KnpMenu.git', 'master')
+);
+
+foreach ($deps as $dep) {
+    list($name, $url, $rev) = $dep;
+
+    echo "> Installing/Updating $name\n";
+
+    $installDir = $vendorDir.'/'.$name;
+    if (!is_dir($installDir)) {
+        system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
+    }
+
+    system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
+}