Skocz do zawartości

Phpunit


Plu

Rekomendowane odpowiedzi

Witam,

nie wiem jak uruchomić PHPUnit.

Instalowałem ręcznie PHPUnit: System->Administracja->Dodaj/Usuń Oprogramowanie.

[root@localhost html]# phpunit  rpm -qa | grep PHPUnit
PHPUnit 3.3.16 by Sebastian Bergmann.

Staram się uruchomić test na podstawie tego artykułu:

http://wortal.php.pl/wortal/artykuly/proce...hpunit/tutorial

Jednak po wprowadzeniu:

 php -f stringtest.php

otrzymuje ten komunikat:

PHP Warning:  require_once(/usr/bin/PHPUnit.php): failed to open stream: No such file or directory in /var/www/html/testcase.php on line 7
PHP Stack trace:
PHP   1. {main}() /var/www/html/stringtest.php:0
PHP   2. require_once() /var/www/html/stringtest.php:3
PHP Fatal error:  require_once(): Failed opening required '/usr/bin/PHPUnit.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/testcase.php on line 7
PHP Stack trace:
PHP   1. {main}() /var/www/html/stringtest.php:0
PHP   2. require_once() /var/www/html/stringtest.php:3

Prosze o pomoc.

PHP mam zainstlowane najnowsze z repo oraz apacha.

Odnośnik do komentarza
Udostępnij na innych stronach

Czy plik /usr/bin/PHPUnit.php istnieje?

Czy uruchamiasz przez suexec?

Czy jest włączony selinux?

1. Tak istnieje tylko z małych liter phpunit.php(nie wiem czy to jakaś różnica) o to jego zawartość:

#!/usr/bin/php
<?php
/* PHPUnit
*
* Copyright ? 2002-2009, Sebastian Bergmann <[email protected]>.
* 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 4572 2009-01-28 07:37:41Z sb $
*/

if (strpos('/usr/bin/php', '@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();
?>

2. suexec nie wiem co to :rolleyes:

3. Myśle, że mam go wyłączonego ale dala pewności:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#	enforcing - SELinux security policy is enforced.
#	permissive - SELinux prints warnings instead of enforcing.
#	disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#	targeted - Targeted processes are protected,
#	mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[Edit]

W plikach php:

require_once '/usr/bin/phpunit.php';

 

Paczki które instalowałem:

httpd

php

mysql

mysql-server

php-mysql

php-pear-PHPUnit

php-channel-phpunit

 

Kurcze nie wiem już sam! :) :) :)

Jeżeli użyję polecenia locate nie znajduje mi tego pliku.

[root@localhost ~]# locate phpunit
/usr/bin/phpunit
/usr/share/pear/.channels/pear.phpunit.de.reg
/usr/share/pear/.channels/.alias/phpunit.txt
/usr/share/pear/.pkgxml/pear.phpunit.de.xml
/usr/share/pear/.registry/.channel.pear.phpunit.de
/usr/share/pear/.registry/.channel.pear.phpunit.de/phpunit.reg
/usr/share/pear/PHPUnit/Extensions/SeleniumTestCase/phpunit_coverage.php
/usr/share/pear/test/PHPUnit/PHPUnit/Tests/phpunit.xml.dist
/var/lib/yum/yumdb/p/8bd17e5589676a6d374e9be06a9ec232ce76a56c-php-channel-phpunit-1.0-3.fc11-noarch
/var/lib/yum/yumdb/p/8bd17e5589676a6d374e9be06a9ec232ce76a56c-php-channel-phpunit-1.0-3.fc11-noarch/from_repo
/var/lib/yum/yumdb/p/8bd17e5589676a6d374e9be06a9ec232ce76a56c-php-channel-phpunit-1.0-3.fc11-noarch/reason
/var/lib/yum/yumdb/p/8bd17e5589676a6d374e9be06a9ec232ce76a56c-php-channel-phpunit-1.0-3.fc11-noarch/releasever

Odnośnik do komentarza
Udostępnij na innych stronach

Pokaż więc zawartość

/var/www/html/testcase.php

/var/www/html/stringtest.php

testcase.php

<?php
/*
testcase.php
*/

require_once 'string.php';
require_once '/usr/bin/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

<?php

require_once 'testcase.php';
require_once '/usr/bin/phpunit.php';

$suite = new PHPUnit_TestSuite("StringTest");
$result = PHPUnit::run($suite);

echo $result -> toString();
?>

Odnośnik do komentarza
Udostępnij na innych stronach

W php.ini włączyłem safe_mode = On

Po wprowadzeniu polecenia "phpunit stringtest.php ":

[root@localhost html]# phpunit stringtest.php
PHP Warning:  shell_exec(): Cannot execute using backquotes in Safe Mode in /usr/share/pear/PHPUnit/Util/Fileloader.php on line 190
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
PHP   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
PHP   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
PHP   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
PHP   7. PHPUnit_Util_Fileloader::syntaxCheck() /usr/share/pear/PHPUnit/Util/Fileloader.php:99
PHP   8. shell_exec() /usr/share/pear/PHPUnit/Util/Fileloader.php:190

Warning: shell_exec(): Cannot execute using backquotes in Safe Mode in /usr/share/pear/PHPUnit/Util/Fileloader.php on line 190

Call Stack:
   0.0004      48596   1. {main}() /usr/bin/phpunit:0
   0.3049    3566160   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
   0.3055    3573376   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
   0.3055    3573436   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
   0.3056    3573612   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
   0.3058    3588260   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
   0.3059    3588368   7. PHPUnit_Util_Fileloader::syntaxCheck() /usr/share/pear/PHPUnit/Util/Fileloader.php:99
   0.3061    3588668   8. shell_exec() /usr/share/pear/PHPUnit/Util/Fileloader.php:190

PHP Warning:  require_once(): Unable to access /usr/bin/phpunit.php in /var/www/html/testcase.php on line 7
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
PHP   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
PHP   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
PHP   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
PHP   7. PHPUnit_Util_Fileloader::load() /usr/share/pear/PHPUnit/Util/Fileloader.php:102
PHP   8. include_once() /usr/share/pear/PHPUnit/Util/Fileloader.php:119
PHP   9. require_once() /var/www/html/stringtest.php:3

Warning: require_once(): Unable to access /usr/bin/phpunit.php in /var/www/html/testcase.php on line 7

Call Stack:
   0.0004      48596   1. {main}() /usr/bin/phpunit:0
   0.3049    3566160   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
   0.3055    3573376   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
   0.3055    3573436   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
   0.3056    3573612   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
   0.3058    3588260   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
   0.3158    3588984   7. PHPUnit_Util_Fileloader::load() /usr/share/pear/PHPUnit/Util/Fileloader.php:102
   0.3263    3592576   8. include_once('/var/www/html/stringtest.php') /usr/share/pear/PHPUnit/Util/Fileloader.php:119
   0.3271    3605320   9. require_once('/var/www/html/testcase.php') /var/www/html/stringtest.php:3

PHP Warning:  require_once(/usr/bin/phpunit.php): failed to open stream: No such file or directory in /var/www/html/testcase.php on line 7
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
PHP   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
PHP   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
PHP   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
PHP   7. PHPUnit_Util_Fileloader::load() /usr/share/pear/PHPUnit/Util/Fileloader.php:102
PHP   8. include_once() /usr/share/pear/PHPUnit/Util/Fileloader.php:119
PHP   9. require_once() /var/www/html/stringtest.php:3

Warning: require_once(/usr/bin/phpunit.php): failed to open stream: No such file or directory in /var/www/html/testcase.php on line 7

Call Stack:
   0.0004      48596   1. {main}() /usr/bin/phpunit:0
   0.3049    3566160   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
   0.3055    3573376   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
   0.3055    3573436   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
   0.3056    3573612   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
   0.3058    3588260   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
   0.3158    3588984   7. PHPUnit_Util_Fileloader::load() /usr/share/pear/PHPUnit/Util/Fileloader.php:102
   0.3263    3592576   8. include_once('/var/www/html/stringtest.php') /usr/share/pear/PHPUnit/Util/Fileloader.php:119
   0.3271    3605320   9. require_once('/var/www/html/testcase.php') /var/www/html/stringtest.php:3

PHP Fatal error:  require_once(): Failed opening required '/usr/bin/phpunit.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/testcase.php on line 7
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
PHP   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
PHP   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
PHP   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
PHP   7. PHPUnit_Util_Fileloader::load() /usr/share/pear/PHPUnit/Util/Fileloader.php:102
PHP   8. include_once() /usr/share/pear/PHPUnit/Util/Fileloader.php:119
PHP   9. require_once() /var/www/html/stringtest.php:3

Fatal error: require_once(): Failed opening required '/usr/bin/phpunit.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/testcase.php on line 7

Call Stack:
   0.0004      48596   1. {main}() /usr/bin/phpunit:0
   0.3049    3566160   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:52
   0.3055    3573376   3. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/pear/PHPUnit/TextUI/Command.php:84
   0.3055    3573436   4. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:201
   0.3056    3573612   5. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/pear/PHPUnit/Runner/BaseTestRunner.php:267
   0.3058    3588260   6. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/pear/PHPUnit/Runner/StandardTestSuiteLoader.php:98
   0.3158    3588984   7. PHPUnit_Util_Fileloader::load() /usr/share/pear/PHPUnit/Util/Fileloader.php:102
   0.3263    3592576   8. include_once('/var/www/html/stringtest.php') /usr/share/pear/PHPUnit/Util/Fileloader.php:119
   0.3271    3605320   9. require_once('/var/www/html/testcase.php') /var/www/html/stringtest.php:3

[Edit]

Może to dlatego, że nie mam biblioteki Pear nie instalowałem.

Możesz podać mi krok po kroku jak ty instalowałeś php.... phpunit?

Odnośnik do komentarza
Udostępnij na innych stronach

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
×
×
  • Dodaj nową pozycję...