![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 550 Pomógł: 9 Dołączył: 29.05.2009 Skąd: Ostrów Wielkopolski Ostrzeżenie: (0%) ![]() ![]() |
Zainstalowałem PHPUnit, w następujący spsób
![]() W wierszu poleceń przeszedłem do c:\xampp\xampp\php\ Wprowadziłem: Kod pear channel-discover pear.phpunit.de pear install phpunit/PHPUnit Wszystko się ładnie zainstalowało. Następnie korzystam z tego wprowadzenia->http://wortal.php.pl/phppl/wortal/artykuly/proces_tworzenia_aplikacji/tlumaczenia/srodowisko_testowe_pear_phpunit/tutorial Tworzę 3 pliki: string.php CODE <?php /* string.php */ class String { //zawiera dane wewnętrzne var $data; // konstruktor function String($data) { $this->data = $data; } // tworzy głęboką kopię obiektu function copy() { } // dodaje kolejny obiekt string do tej klasy function add($string) { } // zwraca sformatuwany string function toString($format) { } } ?> testcase.php CODE <?php /* testcase.php */ require_once 'string.php'; require_once 'C:\xampp\xampp\php\PHPUnit.php'; class StringTest extends PHPUnit_TestCase { // zawiera obiekt obsługujący klasę var $abc; // konstruktor ciągu testów function StringTest($name) { $this->PHPUnit_TestCase($name); } // wywołanie zanim funkcje testujące zostaną wykonane // ta funkcja zdefiniowana jest w PHPUnit_TestCase i nadpisana // tutaj function setUp() { // stwórz nowa instancję String z // ciągiem znaków 'abc' $this->abc = new String("abc"); } // wywołane po wykonaniu funkcji testujących // ta funkcja zdefiniowana jest w PHPUnit_TestCase i nadpisana // tutaj function tearDown() { // usuń swoją instancję unset($this->abc); } // przetestuj funkcję toString function testToString() { $result = $this->abc->toString('contains %s'); $expected = 'contains abc'; $this->assertTrue($result == $expected); } // przetestuj funkcję copy function testCopy() { $abc2 = $this->abc->copy(); $this->assertEquals($abc2, $this->abc); } // przetestuj funkcję add function testAdd() { $abc2 = new String('123'); $this->abc->add($abc2); $result = $this->abc->toString("%s"); $expected = "abc123"; $this->assertTrue($result == $expected); } } ?> stringtest.php CODE <?php require_once 'testcase.php'; require_once 'C:\xampp\xampp\php\PHPUnit.php'; $suite = new PHPUnit_TestSuite("StringTest"); $result = PHPUnit::run($suite); echo $result -> toString(); ?> Następnie próbuje uruchomić test, zauważyłem że w folderze nie ma pliku PHPUnit.php więc go stworzyłem korzystając z pliku phpunit: CODE #!\xampp\xampp\php\php.exe <?php /* PHPUnit * * Copyright © 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: phpunit.php 5078 2009-08-10 07:58:18Z sb $ */ if (strpos('\xampp\xampp\php\php.exe', '@php_bin') === 0) { set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); } require_once 'PHPUnit/Util/Filter.php'; PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); require 'PHPUnit/TextUI/Command.php'; define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main'); PHPUnit_TextUI_Command::main(); ?> Teraz uruchamiam test: Kod C:\xampp\xampp\htdocs\phpunit\phpunit>phpunit stringtest.php ´╗┐#!\xampp\xampp\php\php.exe Fatal error: Cannot redeclare class PHPUnit_TextUI_Command in C:\xampp\xampp\php \PEAR\PHPUnit\TextUI\Command.php on line 70 A teraz pytanie co robię nie tak? ![]() |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 14.08.2025 - 04:46 |