Foren-Übersicht PHPUnit Test

PHPUnit Test

Beitrag 11.01.2007 16:07
elexis_linux Site Admin

Beiträge: 396
Website: http://ModernHosting.ch
Datei email.php

Zuerst phpunit2 Installieren

Code: Alles auswählen

<?PHP class EmailAddress { public $localPart; public $domain; public $address; public function __construct($address = null) { if($address) { $this->address = $address; $this->extract(); } } protected function extract() { list($this->localPart, $this->domain) = explode("@", $this->address); } } ?>

Die Testklasse test.php

Code: Alles auswählen

<?PHP require_once "email.php"; require_once 'PHPUnit2/Framework/TestCase.php'; class EmailAddressTest extends PHPUnit2_Framework_TestCase { public function __constructor($name) { parent::__constructor($name); } function testLocalPart() { $email = new EmailAddress("ranz at domain.ch"); $this->assertTrue($email->localPart == 'franz'); } function testDomain() { $email = new EmailAddress("franz at domain.ch"); $this->assertTrue($email->domain == 'domain.ch'); } } require_once "PHPUnit2/Framework/TestSuite.php"; $suite = new PHPUnit2_Framework_TestSuite(); $suite->addTest(new EmailAddressTest('testLocalPart')); require_once "PHPUnit2/TextUI/TestRunner.php"; PHPUnit2_TextUI_TestRunner::run($suite); ?>

Dann in die Konsolle und so ausführen:

Code: Alles auswählen

phpunit --wait /var/www/html/test/test.php
Folgendes Resultat sollte kommen:

Code: Alles auswählen

PHPUnit 2.3.6 by Sebastian Bergmann. . Time: 0.000646 OK (1 test) PHPUnit 2.3.6 by Sebastian Bergmann.

4 poziom opinie

Zurück zu „PHP Programmieren“



Wer ist online?

Mitglieder in diesem Forum: Bot und 0 Gäste