NotFoundHttpException when I try to run Codeception on Laravel 5 - functional-testing

I am trying to play a little with Codeception in Laravel 5 and I get a NotFoundHttpException.
Can anyone tell me what I did wrong?
Installed (via composer)
"codeception/codeception": "*"
Ran a vendor/bin/codecept bootstrap
Edited tests/functional.suite.yml
class_name: FunctionalTester
modules:
enabled: [Filesystem, FunctionalHelper, Laravel5]
Did a vendor/bin/codecept build
Created a simple functional test in tests\functional\RegisterCept.php
$I = new FunctionalTester($scenario);
$I->wantTo('register a user');
$I->amOnPage('/');
$I->see('online');
Modified the terminate method of vendor/codeception/codeception/src/Codeception/Lib/Connector/Laravel5.php with (due a bug fix research)
public function terminate(DomRequest $request, Response $response)
{
$request = Request::createFromBase($request);
$request->enableHttpMethodParameterOverride();
$this->httpKernel->terminate($request, $response);
}
Ran ./vendor/bin/codecept run functional and test fail at the set I see "online"
In tests\_output\ I see RegisterCept.fail.html with NotFoundHttpException in RouteCollection.php line 145:
Does anyone know how to fix this?

I haven't tried the Laravel 5 connector with the Codeception package itself, but there is a Codeception module for Laravel 5 on GitHub.
Codeception Laravel 5 Module

Related

having issues with laravel 9 breeze , i have hosted it successfully everything working fine ... but breeze login and register wont work on production

this is my error on production level
Vite manifest not found at: /home/codarhqc/codar/public/build/manifest.json (View: /home/codarhqc/codar/resources/views/layouts/guest.blade.php) (View: /home/codarhqc/codar/resources/views/layouts/guest.blade.php)
You can delete the following file bootstrap/cache/config.php or better if you can make a route in your web.php file with a function that runs: php artisan optimize:clear.
This should remove the problem.

How to set up PhpStorm correctly? Сan't run PHPUnit on Laravel 8 on Windows 10. Call to undefined function Tests\Unit\is_id_term()

I have installed PHPUnit globally and set up an environment variable "path" by, so it runs by command phpunit.phar
I created a file with a custom function in the "app" folder:
function is_id_term(string $q, &$id = null, string $name = 'id'): bool {
...
...
...
...
...
}
After that I added at the autoload section in the composer.json file in the following line:
"files": [
"./app/functions.php"
]
Then I ran the command:
composer dump-autoload
Then created unit test in a tests/unit/ folder:
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class IsIdTermTest extends TestCase
{
public function testOne()
{
$res = is_id_term('id: 1');
$this->assertTrue($res);
}
public function testString()
{
$res = is_id_term('id:lucas');
$this->assertFalse($res);
}
}
If I run these tests using the green button in the upper right corner of PhpStorm, I get the following error:
C:\localserver\php8.0.2\php.exe C:\Users\webgr\AppData\Roaming\Composer\vendor\laravel\installer\bin\phpunit.phar --no-configuration C:\Users\webgr\projects\my-blog\tests --teamcity --cache-result-file=C:\Users\webgr\projects\my-blog\.phpunit.result.cache
Testing started at 19:00 ...
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
Error : Call to undefined function Tests\Unit\is_id_term()
C:\Users\webgr\projects\my-blog\tests\Unit\IsIdTermTest.php:11
After starting the test using the green button, file appears in the root folder of the project .phpunit.result.cache with this content
C:37:"PHPUnit\Runner\DefaultTestResultCache":230:{a:2:{s:7:"defects";a:2:{s:32:"Tests\Unit\IsIdTermTest::testOne";i:4;s:35:"Tests\Unit\IsIdTermTest::testString";i:4;}s:5:"times";a:2:{s:32:"Tests\Unit\IsIdTermTest::testOne";d:0.004;s:35:"Tests\Unit\IsIdTermTest::testString";d:0;}}}
But, if I execute the command in terminal:
phpunit.phar
then all tests pass without errors.
In the same way, PhpStorm finds this function without problems if I click on its name while in some other file.
Can you please tell me how to set up PhpStorm? And what is my mistake?
Try replacing
use PHPUnit\Framework\TestCase;
with
use Tests\TestCase;
The artisan make:test {name} --unit command seems to always generate the template with the TestCase referenced as PHPUnit\Framework\TestCase
After reinstalling the project, everything worked by itself, but I still don't know what was the cause of the error. I believe that the reason was that I created the project before I installed PHPUnit globally and configured XDebug. Although of course I could be wrong.

NotFoundHttpException in RouteCollection.php in laravel 5.4

I created a new project via composer create-project laravel/laravel Test 5.4.* then i go to my browser to see my localhost if its working localhost/test/public and it works it redirect me to the welcome page, but when i tried to test
Route::get('/test', function(){
return 'TEST';
});
Then I go to my localhost/test/public/test it shows me error like
NotFoundHttpException: in RouteCollection.php (line 179)
is it a solved issue?
instead of localhost/test/public/test try localhost/test/public/index.php/test.
of course you can use laravel's own server. it is suitable for most developing usages.

Lumen with Dingo API routes not defined

Have a fresh install of Lumen 5.2 and new install of Dingo 1.0.*#dev
I have installed the service provided in bootstrap/app.php
Also setup .env file eg
API_VERSION=v1
API_PREFIX=api
API_SUBTYPE=app
API_DEBUG=true
In the Http/routes.php I have added a test route eg
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api) {
$api->get('example', 'ExampleController#test');
});
This route is not working plus in command line if I try php artisan api:routes
I get error
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "api:routes" is not defined.
Did you mean this?
api:docs
Have I missed something? Also using HTTP Basic if it helps?
In Dingo Documentation -> Creating API Endpoints section you can find this sentence:
"If you're using Laravel 5.1 you can see the registered routes using Artisan.
$ php artisan api:routes
"
If you also run
$ php artisan list
only api:docs is available - api:routes is missing.
That means that this command do not work in Lumen.
composer requires jakubkratina/lumen-dingo-route-list
Add the following code in app/Console/Kernel.php:
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
By default, as shown in docs, lumen don't ship with api:routes. But you can use lumen-dingo-route-list from jakubkratina. It will add route:list to your artisan.
By the way, I'd to do some adjustments to get it working:
First, include the backlash into the registration
protected $commands = [
\JK\Dingo\Api\Console\Commands\RouteListCommand::class
];
And last, edit vendor/jakubkratina/lumen-dingo-route-list/src/RouteListCommand.php and add this code:
public function handle()
{
return $this->fire();
}

Call to undefined method Illuminate\Http\Response::view()

I have Laravel installed and now I keep getting this error everytime I run composer update, php artisan routes, or any composer commands:
Call to undefined method Illuminate\Http\Response::view()
I already searched the internet and tried the following suggested solutions so far and nothing worked:
1) A lot of suggested answer on the net says to delete vendor/compiled.php and run the composer update again. But when I went to vendor folder, I cannot find any compiled.php file there. The only file that exists there is: autoload.php
2) I also tried searching for compiled.php inside storage/framework/ folder and nothing there neither.
3) I even tried running optimize with the --force flag php artisan optimize --force and it shows the same error as above.
4) I looked at boostrap/autoload.php for compiled path and it says $compiledPath = __DIR__.'/cache/compiled.php'; I can only see the boostrap/cache folder and that doesnt have this file.
What is wrong here? I am new to Laravel and I dont understand what this error means. Going by the answers out there, I am going around looking for compiled.php to delete and run the update again and I dont even know if that is the right solution for it. Can someone help me here please on how do I proceed troubleshooting this?
I have Laravel 5.1.6 installed after the update I did yesterday. I also ran the composer dumpautoload command today and I wonder if this error started happening after that. Now any commands in composer is giving the above error.
EDIT:
Now even my browser view of the site is showing the error:
FatalErrorException in Facade.php line 210:
Call to undefined method Illuminate\Foundation\Application::missing()
I also tried deleting the complete vendor folder and composer.lock, and re-ran composer install. Towards the end of the installation when generating autoload files, it showed this error again and stopped.
EDIT 2:
#NehalHasnayeen in the comments got it absolutely right. This error was caused due to app calling the view method on Response class, while the response class had no view method. Once I removed that from my route, it worked. This is my route file:
Route::get('/', function () {
return view('index');
//return View::make('index');
});
Route::group(['prefix' => 'api'], function()
{
Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]);
Route::post('authenticate', 'AuthenticateController#authenticate');
});
// -------- THIS WAS CAUSING THE ISSUE - REMOVING THIS WORKED AFTER THAT ------
//App::missing(function($exception) {
// return view('index');
//});
It takes me to my final question, why was the catch-all route throwing this error? I read from here that adding the above will redirect all other route requests to index. What is the right method? Did it change in Laravel 5 or have I done something wrong?
For 1st error:
your app is calling view method on Response class, but response class has no view method, so find the file where it is calling this method & remove it & replace it with correct method
For 2nd error:
App::missing is for laravel 4 version, it is removed in laravel 5. To achieve the same in your app\exceptions\handler.php file add this in render method
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
return response()->view('index', [], 404);
}
return parent::render($request, $e);
}

Resources