我似乎有與執行PHPUnit測試在Zend框架2.ZendFramework 2 - PHPUnit的 - 命令行工作,NetBeans的:「沒有執行的測試」
OS自己的模塊一個小問題:MAC OS 10.8.3
的Zend Framework 2.1.4
PHPUnit的版本3.7.19(通過安裝梨)
PHP版本(啓用了XDebug,版本2.1.3)5.3.15
我跟隨了Zend方針的指示,創建模塊「Album」(http://framework.zend.com/manual/2.1/en/user-guide/modules.html)
我不想將單元測試放入模塊文件夾中,而是將它們全部放在一個集中文件夾中。這是我的應用程序的基本結構:
-config
-data
- 模
-public
-tests
--modules
---專輯
---- AlbumTest。 PHP
--Bootstrap.php
--phpunit.xml
-vendor
...(許可證,自述,compos ers和init_autoloader.php)
- > Module Album的測試位於「tests」中的「Modules/Album」文件夾中。 「測試」文件夾還包含Bootstrap.php和phpunit.xml。
這裏是文件的內容:
bootstrap.php中
<?php
/*
* Set error reporting to the level to which Zend Framework code must comply.
*/
error_reporting(E_ALL | E_STRICT);
/*
* The first run required me to fix some constants
*/
defined('TESTS_ZEND_FORM_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_FORM_RECAPTCHA_PUBLIC_KEY', 'public key');
defined('TESTS_ZEND_FORM_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_FORM_RECAPTCHA_PRIVATE_KEY', 'private key');
defined('TESTS_ZEND_LDAP_PRINCIPAL_NAME') || define('TESTS_ZEND_LDAP_PRINCIPAL_NAME', '[email protected]');
defined('TESTS_ZEND_LDAP_ALT_USERNAME') || define('TESTS_ZEND_LDAP_ALT_USERNAME', 'anotherUser');
chdir(dirname(__DIR__));
/*
* autoload the application
*/
include __DIR__ . '/../init_autoloader.php';
Zend\Mvc\Application::init(include 'config/test.config.php');
phpunit.xml
<phpunit bootstrap="./Bootstrap.php" colors="true">
<testsuites>
<testsuite name="Zend Module Tests">
<directory>./Modules</directory>
</testsuite>
</testsuites>
</phpunit>
AlbumTest.php
<?php
namespace AlbumTest\Model;
use Album\Model\Album;
use PHPUnit_Framework_TestCase;
/**
* @category Module
* @package Album
* @subpackage UnitTests
* @group Module_Album
*/
class AlbumTest extends PHPUnit_Framework_TestCase {
public function testAlbumInitialState() {
$album = new Album();
$this->assertNull($album->artist, '"artist" should initially be null');
$this->assertNull($album->id, '"id" should initially be null');
$this->assertNull($album->title, '"title" should initially be null');
}
public function testExchangeArraySetsPropertiesCorrectly() {
$album = new Album();
$data = array('artist' => 'some artist',
'id' => 123,
'title' => 'some title');
$album->exchangeArray($data);
$this->assertSame($data['artist'], $album->artist, '"artist" was not set correctly');
$this->assertSame($data['id'], $album->id, '"id" was not set correctly');
$this->assertSame($data['title'], $album->title, '"title" was not set correctly');
}
public function testExchangeArraySetsPropertiesToNullIfKeysAreNotPresent() {
$album = new Album();
$album->exchangeArray(array('artist' => 'some artist',
'id' => 123,
'title' => 'some title'));
$album->exchangeArray(array());
$this->assertNull($album->artist, '"artist" should have defaulted to null');
$this->assertNull($album->id, '"id" should have defaulted to null');
$this->assertNull($album->title, '"title" should have defaulted to null');
}
public function testGetArrayCopyReturnsAnArrayWithPropertyValues() {
$album = new Album();
$data = array('artist' => 'some artist',
'id' => 123,
'title' => 'some title');
$album->exchangeArray($data);
$copyArray = $album->getArrayCopy();
$this->assertSame($data['artist'], $copyArray['artist'], '"artist" was not set correctly');
$this->assertSame($data['id'], $copyArray['id'], '"id" was not set correctly');
$this->assertSame($data['title'], $copyArray['title'], '"title" was not set correctly');
}
public function testInputFiltersAreSetCorrectly() {
$album = new Album();
$inputFilter = $album->getInputFilter();
$this->assertSame(3, $inputFilter->count());
$this->assertTrue($inputFilter->has('artist'));
$this->assertTrue($inputFilter->has('id'));
$this->assertTrue($inputFilter->has('title'));
}
}
NetBeans的人都知道,在那裏找到t他phpunit的二進制文件: (我想在這裏發佈圖片,雖然沒有聲望:),我會嘗試解釋它) 在選項中配置的路徑 - php - 單元測試
/usr/local /梨/斌/ PHPUnit的
和 在/ usr /本地/梨/斌/ PHPUnit的-skelgen
在項目的屬性我設置了「使用XML配置」並粘貼路徑phpunit.xml。我還檢查了「在運行測試前詢問測試組」 - 我將測試放在「Module_Album」組之上,就像我確信的那樣,PHPUnit找到了正確的測試。
我右鍵點擊項目,選擇「測試」,它顯示我的組「Module_Album」,我檢查它,然後單擊「確定」。它運行一些東西,告訴我它位於正確的phpunit.xml(「從FULL_PATH/tests/phpunit.xml中讀取配置」)。運行後,它告訴我,它沒有執行任何測試。
這是在NetBeans的全部輸出:
PHPUnit 3.7.19 by Sebastian Bergmann.
Configuration read from FULL_PATH/tests/phpunit.xml
Time: 9 seconds, Memory: 348.25Mb
[2KNo tests executed!
[2K
Generating code coverage report in Clover XML format ... done
無論如何,我可以通過殼(終端)在成功這樣做。無關緊要,如果我直接安裝tests目錄並運行phpunit,請使用phpunit二進制文件的完整路徑(以確保我沒有使用不同的版本),指定phpunit.xml的完整路徑,等等。下面是一些樣本:
phpunit
phpunit -c FULL_PATH/tests/phpunit.xml
/usr/local/pear/bin/phpunit -c FULL_PATH/tests/phpunit.xml
所有這些命令給我,我的期望:
PHPUnit 3.7.19 by Sebastian Bergmann.
Configuration read from FULL_PATH/tests/phpunit.xml
.....
Time: 0 seconds, Memory: 12.75Mb
OK (5 tests, 16 assertions)
- 我不明白,爲什麼這個工程外殼,但不是通過NetBeans的
- NetBeans使用350MB,而在shell中只使用12.75MB
- 如果我刪除「在運行測試前詢問測試組」選項,它似乎嘗試運行所有ZendTest。不知道這是怎麼可能的,從phpunit.xml中它不應該找到它們。
任何幫助表示讚賞,謝謝!