2013-04-12 28 views
18

Ho un piccolo problema quando sto cercando di eseguire PHPUnit test in IDP PhpStorm.Errore quando provo a eseguire PHPUnit da PhpStorm

Io uso di file compositore che sembra:

{ 
    "require": { 
     "phpunit/phpunit": "3.7.19" 
    } 
} 

Ora quando corro prova ho recive eccezione: PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.'

Cosa c'è di sbagliato? Quando ho incluso il test di versione pera funzionante, OK.

// EDIT Campione classe di test:

class ReaderTest extends PHPUnit_Framework_TestCase 
    { 
     /** 
     * @test 
     */ 
     public function shouldGetReadedValue() 
     { 
      $this->assertTrue(true); 
     } 
    } 

// EDIT2 Trace:

/usr/bin/php /tmp/ide-phpunit.php --no-configuration /path/to/my/project 
Testing started at 14:53 ... 
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.' in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:183 
Stack trace: 
#0 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(315): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass)) 
#1 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(389): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass)) 
#2 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('/var/www/php-sh...') 
#3 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Runner/BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array) 
#4 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('/var/www/php-sh...', '', A in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php on line 183 

Process finished with exit code 255 
+1

Potete mostrare il test dell'unità? La tua classe di test estende PHPUnit_Framework_TestCase? –

+1

Modifica la mia domanda e aggiungo una classe di test di esempio. Ho poche lezioni di prova. –

risposta

12

Ho trovato la soluzione a questo problema.

In Modifica configurazioni nella directory ho impostato il percorso al mio catalogo di test (/path/to/my/project/tests), dopo che questi test sono stati eseguiti correttamente.

+2

È importante notare che il percorso deve essere impostato tramite: 'Esegui> Modifica configurazione> PhpUnit' Lì,' Directory' può essere impostato. Non lo trovate (!) In "File> Impostazioni" in PhpStorm. – k0pernikus

0

All'interno del PHPUnit_Framework_TestSuite, questo codice exists in the constructor:

if (!$theClass->isSubclassOf('PHPUnit_Framework_TestCase')) { 
    throw new PHPUnit_Framework_Exception(
     'Class "' . $theClass->name . '" does not extend PHPUnit_Framework_TestCase.' 
    ); 
} 

vedo nella tua esempio che si sta estendendo PHPUnit_Framework_TestCase ma l'errore suggerisce che si sta utilizzando PHPUnit_Extensions_RepeatedTest che si estende PHPUnit_Extensions_TestDecorator che in ultima analisi si estende PHPUnit_Framework_Assert

PHPUnit_Framework_Assert 
    | 
    --PHPUnit_Extensions_TestDecorator 
     | 
     --PHPUnit_Extensions_RepeatedTest 

doppio controllare i test perché l'errore suggerisce che si sta tentando di eseguire un TestSuite che utilizza un test che estende PHPUnit_Extensions_RepeatedTest. Stavi invece cercando di estendere PHUnit usando Test Decorator?

http://docs.tadiavo.com/phpunit/www.phpunit.de/pocket_guide/3.1/en/extending-phpunit.html

Questo è tutto il consiglio che posso offrire attualmente senza vedere i test reali e come si sta li esegue.

+0

OK, ma perché quando eseguo il test dalla console tutto è OK? Sono abbastanza sicuro che il mio test sia buono. Quando utilizzo PHPUnit come include la libreria esterna e imposta la configurazione appropriata in PhpStorm funziona correttamente. –

+0

La tua domanda ha dichiarato che non funziona in PHPStorm. Forse hai configurato l'IDE in modo errato e ora funziona? –

+0

Mi è stato configurato IDE come nel manuale. Aggiungo la dipendenza con successo quindi imposto il caricatore personalizzato su 'vendor/autoload.php'. Questo è tutto ciò che ho fatto. –

5

Ho lo stesso problema quando uso il compositore.

La soluzione è inserire il file di test nella propria directory. Ecco la mia phpunit funzionante, ho messo tutti i miei test nella directory test.

<phpunit bootstrap="vendor/autoload.php" 
    colors="true" 
    convertErrorsToExceptions="true" 
    convertNoticesToExceptions="true" 
    convertWarningsToExceptions="true" 
    stopOnFailure="true"> 
    <testsuites> 
     <testsuite name="Test Suite"> 
      <directory>test</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

spero che risolve se qualcuno ha lo stesso problema .. :)

5

Questo è ciò che ha funzionato per me, grazie alla risposta di Piotr sopra, ma io sto fornendo con un po 'più in dettaglio esatto qui tutto il passi che dovevo fare:

passaggi per farlo funzionare (test in PhpStorm 8.0.1):

1) inPreferences > PHP > PHPUnitfare in modo che nulla sia impostato per la configurazione di default f ile o file di bootstrap predefinito.

2) Fai una configurazione PHPUnit personalizzato tramiteRun > Edit Configurations >nelCommand Linecomma, ed essere sicuri di:

a) setCustom working directory:essere/absolute/path/to/vendor.

b) selezionare "Usa file di configurazione alternativo:" e impostarlo su/absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist

Quindi è possibile eseguire qualsiasi classe di test nella suite specificando la classe e il file, o semplicemente controllare "definito nella configurazione file "per eseguirli tutti in base alla configurazione.

Problemi correlati