【问题标题】:vsfStream with cakephp 2.0 and PHPUnitvsfStream 与 cakephp 2.0 和 PHPUnit
【发布时间】:2014-03-05 18:15:19
【问题描述】:

我目前正在为处理文件的 Image 模型构建一些测试,并希望使用 vsfStream 来测试文件操作。

我似乎无法让我的测试识别 vsfClass。

vsfStream 库位于 app/Vendor/vsfStream

我的 ImageTest.php 文件如下:

 <?php
 App::uses('Image', 'Model');
 App::uses('vfsStream', 'Vendor');
 //App::import('Vendor', 'vfsStream', array('file' => 'vfsStream' . DS . 'vfsStream.php'));
 /**
  * Image Test Case
  *
  */
  class ImageTest extends CakeTestCase {

  /**
   * Fixtures
   *
   * @var array
   */
      public $fixtures = array(
    'app.image',
    'app.contractor',
    'app.project',
    'app.project_contractor',
    'app.project_image'
  );

 /**
  * setUp method
  *
  * @return void
  */
      public function setUp() {
    parent::setUp();
    $this->Image = ClassRegistry::init('Image');
            $this->root = vfsStream::setup('exampleDir');
  }

 ...more code

我得到了错误

错误:找不到类“vfsStream” 文件:C:\xampp\htdocs\sgaluminium\app\Test\Case\Model\ImageTest.php 线路:32

任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: php unit-testing phpunit cakephp-2.4


    【解决方案1】:

    似乎没有正确加载 vsfStream。你用作曲家加载它吗?我建议你使用这个作曲家插件:https://github.com/uzyn/cakephp-composer(阅读他们网站上的使用方法部分)然后你像这样编写你的 composer.json:

    {
        "require-dev": {
            "phpunit\/phpunit": "3.7.35",
            "mikey179/vfsStream": "1.2"
        }
    }
    

    此设置在我的项目中运行良好。在我的测试文件中,我使用:

    App::uses('vfsStream', 'Vendor');
    

    就像你一样。

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 2011-08-31
      • 1970-01-01
      • 2012-03-27
      • 2012-09-18
      • 2012-04-18
      • 2012-02-10
      • 2012-04-13
      • 1970-01-01
      相关资源
      最近更新 更多