I'm giving Laravel 5 (4.3) a go and have tried writing some simple controller tests like so:
public function testIndex()
{
$this->call('GET', 'posts');
$this->assertResponseOk();
}
When I run the test I get an error:
ErrorException: Undefined property: PostsControllerTest::$client
Why has the client attribute disappeared from the test class in Laravel 5?
Functions like
$this->assertResponseOk();
are not available in the current build of Laravel 5. I'm not sure if Taylor plans to reintroduce them.
I think you can add the following package to get back some of the functionality
https://github.com/orchestral/testbench
Related
I have this code:
class TotersProviderLoginController extends Controller
{
private $oauthService;
public function __construct(Request $request)
{
$provider = $request->route()->parameter('provider'); // error here
if($provider == 'google')
$this->oauthService = new GoogleOauthService();
else
throw new \Exception('Provider '.($provider ?? '').' not supported!');
}
I have the following routes defined:
Route::get('login/toters/{provider}', 'Accounts\TotersProviderLoginController#redirectToProvider');
Route::get('login/toters/{provider}/redirect', 'Accounts\TotersProviderLoginController#handleProviderCallback');
Route::get('login/toters/{provider}/csrf', 'Accounts\TotersProviderLoginController#getCsrf');
Route::post('login/toters/{provider}/oauth', 'Accounts\TotersProviderLoginController#requestToken');
for some reason when I run
php artisan route:list --verbose
I get this error
In TotersProviderLoginController.php line 38:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to a member function parameter() on null
so it's clear that $request->route() is returning null. Why is that?
note: I'm using Laravel 5.8
I have debug myself as you mentioned in the question and i found the way where you get the error.
When you run php artisan route:list --verbose command it will debug all routes and also call controller methods of every routes.
In your case what happens when you run command with verbose, route do not have provider default value and that's why it always gives null value.
While you call routes via postman or web it will definitely work, because at that time you have always some value for provider.
Thanks:)
I am attempting to generate a php-symfony server stub using swagger-codgen but I am not getting an index.php (or app.php or anything like that).
When I generate a server stub using the php-silex preset I get an index.php. If I google "silex .htaccess" I can easily find the mod_rewrite directives to get it working. However, when I generate code using the php-symfony preset I cannot find the entry point.
I attempted to combine the php-silex and php-symfony generated codebases (since silex is a symfony project) like so:
(index.php):
use Swagger\Server\Controller\GetTypesListController;
$app->GET('/image/list/types', function (Application $app, Request $request) {
$tlc = new GetTypesListController();
$response = $tlc->getTypeListAction($request);
return $response;
//new Response('How about implementing getTypeList as a GET method ?');
});
However, then I get errors like:
"Fatal error: Uncaught Error: Call to a member function getApiHandler() on null"
I modified the getApiHandler function of my generated GetTypesListController to instantiate the apiServer variable:
public function getApiHandler()
{
if (!isset($this->apiServer)){
$this->apiServer = new \Swagger\Server\Api\ApiServer();
}
return $this->apiServer->getApiHandler('getTypesList');
}
but this just gave me another error:
Undefined property: Swagger\Server\Controller\GetTypesListController::$container
(referencing SymfonyBundle-php/Controller/Controller.php on line 149)
I am obviously doing something wrong. I would really appreciate being pointed in the right direction.
Edit: I do realize that I'm not supposed to call controllers inside controllers.. I assume that I'm not supposed to combine these two generated codebases at all.
Today, I want to use Laravel Breadcrumbs package with laravel 5.4. I used that with laravel 5.3 without any problem and all things worked fine.
But when run the application I got this error :
FatalErrorException in ServiceProvider.php line 34:
Call to undefined method Illuminate\Foundation\Application::share()
I searched for that and I found that As of laravel 5.4 share has been removed. and I must to use the singleton instead.
But when I did that changes In the ServiceProvider.php like this :
public function register()
{
$this->app['breadcrumbs'] = $this->app->singleton(function($app)
{
$breadcrumbs = $this->app->make('DaveJamesMiller\Breadcrumbs\Manager');
$viewPath = __DIR__ . '/../views/';
$this->loadViewsFrom($viewPath, 'breadcrumbs');
$this->loadViewsFrom($viewPath, 'laravel-breadcrumbs'); // Backwards-compatibility with 2.x
$breadcrumbs->setView($app['config']['breadcrumbs.view']);
return $breadcrumbs;
});
}
I got another error. like this :
ErrorException in Container.php line 1057:
Illegal offset type in unset
I do not know what is problem. can anyone help me ?
Update :
I found the solution Here.
The first problem is that the singleton instance expects a class to bind to as the first argument, which in this case is 'breadcrumbs'.
The second problem is that you don't need to explicitly declare the array key for the singleton instance. So this is how it should look:
$this->app->singleton('breadcrumbs', function($app)
The next problem is that the package you're using has been abandoned. The developer will no longer maintain it.
The final problem is that you're using a version < 3.0.2. So change the version in your composer.json to 3.0.2 and then install that, then you shouldn't need to be modifying any files.
I installed phalcon 3.0.1-14 on an Ubuntu 14.04 box. Also installed Phalcon DevTools (3.0.1).
Initially, I enabled the webtools and when I visit that page, some warnings appear all the time:
Cannot bind an instance to a static closure in /home/pish/vendor/phalcon/devtools/scripts/Phalcon/Web/Tools.php
Cannot bind an instance to a static closure in /home/pish/vendor/phalcon/devtools/scripts/Phalcon/Web/Tools/views/index.phtml
I just ignored them and tried to create a model out of an existing table in the database. When I clicked on "Generate" button
I get the following error:
Phalcon\Mvc\Dispatcher\Exception: ModelsController handler class cannot be loaded
and the model is not created. I tested creating a controller as well, but a similar error occurred and the controller
was not created either.
Finally, I created the model via the console phalcon model users and it was created successfully.
I noticed, though, that the validation function created by the developer tools doesn't work and causes the following
error when I try to create a user:
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\Email given in...
My question is basically, is there something bad with the version of developer tools I installed that causes the problems
with the Webtools and the functions that are generated for models/controllers, etc.? Or I might have something wrong
in my system?
Cannot bind an instance to a static closure
https://github.com/phalcon/cphalcon/issues/11029
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate()
Fixed in the 3.0.x branch (will be released soon)
Regarding your second error message:
Catchable fatal error: Argument 1 passed to Phalcon\Mvc\Model::validate() must implement interface Phalcon\ValidationInterface, instance of Phalcon\Mvc\Model\Validator\Email given in...
Model validation has changed in Phalcon 3.0. In Phalcon v2 you had to do
public function validation()
{
$this->validate(
new Phalcon\Mvc\Model\Validator\Email(['field' => 'email']);
);
if ($this->validationHasFailed() == true) {
return false;
}
}
But the Phalcon\Mvc\Model\Validation is deprecated in v3 and you should use Phalcon\Validation instead. Just alter your code to the following:
public function validation()
{
$validator = new Validation();
$validator->add(
'email', //your field name
new Phalcon\Validation\Validator\Email([
'model' => $this,
'message' => 'Please enter a correct email address'
])
);
return $this->validate($validator);
}
Maybe the DevTools haven't updated this part yet, I am not sure.
I'm using the following Helper: http://pastebin.com/qBs2GvG4 in my CakePHP 2.0 app to show a gravatar for a user like so:
<?php $this->Gravatar->image($profile['User']['email'], array('default'=>'mm','size'=>48)); ?>
However it gives the error:
Fatal error: Call to a member function image() on a non-object in /Users/cameron/Sites/social/app/View/Helper/GravatarHelper.php on line 97
Any ideas what the problem is? This worked in my 1.3 app so wondering if something has changed between 1.3 and 2.0 that causes this issue? Thanks
Helpers have slightly different dependencies in 2.0, especially if they require other helpers.I actually made the commits to fix this one in the CakeDC utils plugin.
You can find an updated version of that helper here: https://github.com/CakeDC/utils/blob/2.0/View/Helper/GravatarHelper.php
Looks like the GravatarHelper has a dependency on the HtmlHelper. Is Html in your list of helpers in the controller?