내가 젠드 프레임 워크 (2)ZendFramework - 2 - phpunit을 명령 줄 작품은, NetBeans는 "실행 없음 테스트"
OS에서 자신의 모듈 phpunit을 시험을 수행하기에 약간의 문제를 갖고있는 것 같다없는 상태
는 젠드 프레임 워크는 2.1.4
phpunit을 버전 3.7.19은 5.3.15 (Xdebug는 활성화 버전 2.1.3) (배를 통해 설치)
PHP 버전
단위 테스트를 모듈 폴더에 넣는 대신 하나의 중앙 집중식 폴더에 모든 모듈을 넣을 수 있습니다.
-config
- 데이터
-module
-public
-tests
--Modules
--- 앨범
---- AlbumTest이 내 응용 프로그램의 기본 구조입니다. PHP
--Bootstrap.php
--phpunit.xml
-vendor
(라이센스, 추가 정보, 합성물 ers 및 init_autoloader.php)
-> 모듈 앨범 테스트는 "테스트"의 "모듈/앨범"폴더에 있습니다. "tests"폴더에는 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에서 읽은 구성")이 위치했음을 알려줍니다. 달리기가 끝나면 아무 테스트도 수행하지 않는다고 알려줍니다.
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
어쨌든, 쉘 (터미널)를 통해 성공적으로 같은 작업을 수행 할 수 있습니다
이 넷빈즈의 최대 출력이다. 그것은 문제가되지 않습니다. 직접 테스트 디렉토리를 마운트하고 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는 350MB를 사용하지만 셸에서는 12.75MB 만 사용합니다.
- "테스트를 실행하기 전에 테스트 그룹 요청"옵션을 제거하면 모든 ZendTest를 실행하는 것으로 보입니다. 이것이 가능하지 않다는 것을 phpunit.xml에서 발견 할 수 없다.
감사합니다.