로컬 작성기 내에서 PHPUnit 4.2.2를 실행 중입니다. 또한 PHP CodeSniffer 2.2.0을 실행하고 있습니다. 내가 메소드 이름을 변경할 때까지,PHPUnit에서 메소드 이름을 변경할 수 없습니다.
<?php
include_once 'animals/Cat.php';
class CatAgeTest extends PHPUnit_Framework_TestCase{
public function testTrueIsTrue(){
$kittyAgeTest = new Cat("steak");
$result = $kittyAgeTest->getAge() >=5 && $kittyAgeTest->getAge() <= 10;
$this->assertTrue($result);
}
}
?>
그것은 전달합니다
나는이 단위 테스트를 작성했습니다. 그것은 내가 바꾼 유일한 것입니다, 그리고 나는 많은 다른 이름을 시도했습니다. 다음은 몇 가지 예입니다.
testCatAgeBetweenFiveAndTen
catAgeTest
catAgeShouldBeBetweenFiveAndTen
... 등등. 다른 프로젝트에서 동일한 구성 - - 같은 컴퓨터에서 나는 여러 가지 다른 단위 테스트를
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
:
여기 내 phpunit.xml입니다. 이름 변경을 시도했지만 실패하지는 않습니다.
내가 PHP 장치를 실행하려면 다음 명령을 사용했습니다 : 여기
vendor/bin/phpunit
vendor/bin/phpunit tests/CatAgeTest.php
내 composer.json 파일입니다 (다만 경우에 도움이됩니다) :
{
"require": {
},
"require-dev": {
"phpunit/phpunit": "4.2.2",
"squizlabs/php_codesniffer": "2.2.0"
},
"autoload": {
"psr-0": {
"animals": ""
}
}
}
어떤 도움을 크게 감상 할 수있다 !
편집 :
가 여기 내 Cat.php 파일입니다 : 여기
입니다 :
<?php
Class Animal {
protected $name;
protected $age;
protected $favoriteFood;
public function __construct($name, $age, $favoriteFood) {
$this->name = $name;
$this->age = $age;
$this->favoriteFood = $favoriteFood;
}
public function getName() {
return $this->name;
}
public function getAge() {
return $this->age;
}
public function getFavoriteFood() {
return $this->favoriteFood;
}
public function setName ($newName) {
$this->name = $newName;
}
public function setAge ($newAge) {
$this->age = $newAge;
}
public function setFavoriteFood($newFavoriteFood) {
$this->favoriteFood = $newFavoriteFood;
}
}
?>
Edit2가 : 여기
<?php
include_once("Animal.php");
class Cat extends Animal{
protected $name;
protected $species;
protected $speakCount;
protected $age;
public function __construct($name = "MewMew") {
$this->name = $name;
$this->age = rand(5, 10); // Random age
$this->species = "Feline"; // For testing in the DB
$this->namesHist = array(); // Names history
array_push($this->namesHist, $name);
}
public function getAge(){
return $this->age;
}
public function getSpecies(){ // For testing in the DB
return $this->species;
}
public function speak($word = "Meow.") { // Spoken word and word count
$this->speakCount += 1;
$this->speakCount % 5 == 0 ? $this->age += 1 : $this->age;
return $word;
}
public function getSpeakCount() {
return $this->speakCount;
}
public function setName ($newName) {
$this->name = $newName;
array_push($this->namesHist, $newName);
}
public function getNames() {
return $this->namesHist;
}
public function getAverageNameLength() {
$nameLen=0;
foreach($this->namesHist as $i) {
$nameLen += strlen($i);
}
$avgNL = round($nameLen/(count($this->namesHist)), 2);
return "Average Name Length: " . $avgNL;
}
}
?>
... 그리고 내 Animal.php 파일입니다 오류가 발생했습니다.
PHPUnit 4.2.2 by Sebastian Bergmann.
Configuration read from /var/www/php/misc/ap/phpunit.xml
F
Time: 15 ms, Memory: 2.75Mb
There was 1 failure:
1) Warning
No tests found in class "CatAgeTest".
FAILURES!
Tests: 1, Assertions: 0, Failures: 1.
것은 당신이 이름을 변경 한 후지고 오류 메시지를 제공합니다. – Mantas
게시물에 오류를 추가했습니다. 감사합니다 ... – fra
'testCatAgeBetweenFiveAndTen()'은 유효한 테스트 이름이어야합니다. 다른 것들은'test *'라는 public method가 아니기 때문에 예상대로 실패 할 것입니다. https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html –