Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [inny][Laravel5] Problem z phpSpec - testy z wykorzystaniem modelu
Pyton_000
post
Post #1





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Mam sobie bardzo prosty test:
  1. <?php
  2.  
  3. namespace spec\App\Repositories;
  4.  
  5. use Laracasts\TestDummy\Factory;
  6. use PhpSpec\ObjectBehavior;
  7. use Prophecy\Argument;
  8.  
  9. class ProgramRepositorySpec extends ObjectBehavior
  10. {
  11. function it_is_initializable()
  12. {
  13. $this->shouldHaveType('App\Repositories\ProgramRepository');
  14. }
  15.  
  16. function it_returns_empty_collection()
  17. {
  18. $this->getActivePrograms()->shouldHaveCount(0);
  19. }
  20.  
  21. function it_returns_only_active_programs()
  22. {
  23. Factory::times(3)->build('App/Program');
  24. $this->getActivePrograms()->shouldHaveCount(3);
  25. }
  26. }

i repozytorium do testu:
  1. <?php namespace App\Repositories;
  2.  
  3. use App\Program;
  4.  
  5. class ProgramRepository {
  6.  
  7. public function getActivePrograms()
  8. {
  9. return Program::active()->get();
  10. }
  11. }


Po odpaleniu requestu jest ok, po odpaleniu phpSpec dostaję stack z błędami:
Kod
PHP Fatal error:  Call to a member function connection() on a non-object in /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 3155
PHP Stack trace:
PHP   1. {main}() /home/testDummy/.composer/vendor/phpspec/phpspec/bin/phpspec:0
PHP   2. Symfony\Component\Console\Application->run() /home/testDummy/.composer/vendor/phpspec/phpspec/bin/phpspec:26
PHP   3. PhpSpec\Console\Application->doRun() /home/testDummy/.composer/vendor/symfony/console/Symfony/Component/Console/Application.php:126
PHP   4. Symfony\Component\Console\Application->doRun() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Console/Application.php:75
PHP   5. Symfony\Component\Console\Application->doRunCommand() /home/testDummy/.composer/vendor/symfony/console/Symfony/Component/Console/Application.php:195
PHP   6. Symfony\Component\Console\Command\Command->run() /home/testDummy/.composer/vendor/symfony/console/Symfony/Component/Console/Application.php:882
PHP   7. PhpSpec\Console\Command\RunCommand->execute() /home/testDummy/.composer/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
PHP   8. PhpSpec\Runner\SuiteRunner->run() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Console/Command/RunCommand.php:113
PHP   9. PhpSpec\Runner\SpecificationRunner->run() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Runner/SuiteRunner.php:56
PHP  10. PhpSpec\Runner\ExampleRunner->run() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Runner/SpecificationRunner.php:54
PHP  11. PhpSpec\Runner\ExampleRunner->executeExample() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Runner/ExampleRunner.php:80
PHP  12. ReflectionMethod->invokeArgs() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Runner/ExampleRunner.php:141
PHP  13. spec\MyLead\Repositories\ProgramRepositorySpec->it_returns_empty_collection() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Runner/ExampleRunner.php:141
PHP  14. spec\MyLead\Repositories\ProgramRepositorySpec->getActivePrograms() /home/testDummy/Code/application.app/spec/Repositories/ProgramRepositorySpec.php:18
PHP  15. PhpSpec\ObjectBehavior->__call() /home/testDummy/Code/application.app/spec/Repositories/ProgramRepositorySpec.php:18
PHP  16. call_user_func_array() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/ObjectBehavior.php:136
PHP  17. PhpSpec\Wrapper\Subject->getActivePrograms() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/ObjectBehavior.php:136
PHP  18. PhpSpec\Wrapper\Subject->__call() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/ObjectBehavior.php:0
PHP  19. PhpSpec\Wrapper\Subject\Caller->call() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Wrapper/Subject.php:188
PHP  20. PhpSpec\Wrapper\Subject\Caller->invokeAndWrapMethodResult() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Wrapper/Subject/Caller.php:89
PHP  21. call_user_func_array() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Wrapper/Subject/Caller.php:256
PHP  22. MyLead\Repositories\ProgramRepository->getActivePrograms() /home/testDummy/.composer/vendor/phpspec/phpspec/src/PhpSpec/Wrapper/Subject/Caller.php:256
PHP  23. MyLead\Program::active() /home/testDummy/Code/application.app/app/Repositories/ProgramRepository.php:9
PHP  24. Illuminate\Database\Eloquent\Model::__callStatic() /home/testDummy/Code/application.app/app/Repositories/ProgramRepository.php:9
PHP  25. call_user_func_array() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3358
PHP  26. MyLead\Program->active() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3358
PHP  27. Illuminate\Database\Eloquent\Model->__call() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:0
PHP  28. Illuminate\Database\Eloquent\Model->newQuery() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3342
PHP  29. Illuminate\Database\Eloquent\Model->newQueryWithoutScopes() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1833
PHP  30. Illuminate\Database\Eloquent\Model->newBaseQueryBuilder() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1859
PHP  31. Illuminate\Database\Eloquent\Model->getConnection() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1918
PHP  32. Illuminate\Database\Eloquent\Model::resolveConnection() /home/testDummy/Code/application.app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3121


Wersja Laravela najnowsza z gałęzi dev. W domyśle mam że to jakiś problem ze startowaniem aplikacji laravela przez spec'a, ale nie udało mi się póki co znaleźć rozwiązania. Może ktoś, coś?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
by_ikar
post
Post #2





Grupa: Zarejestrowani
Postów: 1 798
Pomógł: 307
Dołączył: 13.05.2009
Skąd: Gubin/Wrocław

Ostrzeżenie: (0%)
-----


Będziesz tego rozszerzenia dla phpspec potrzebować: https://github.com/BenConstable/phpspec-laravel tyle że wsparcie dla l5 jest dopiero w drodze, nie wiem jaki jest progres, to już będziesz musiał sam sprawdzić.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 23:45