We have just been discussing mocking calls to external APIs.
One way of doing this, is using php-vcr (https://laracasts.com/lessons/testing-http-requests).
This video looks a little old (2014).
Is this still the recommended way?
MickBee started a new conversation Include External CSS And JS In Single Page Component.
How should I be doing this?
I only want these files to be loaded, when the component is loaded.
Nice one, that is an interesting way of doing things. I'm not sure that I want to go that far, I like just having a controller for each model. I think this makes it easier to find code if you are not familiar with the application.
Having said that, I do like his first rule: Nested resource = new controller.
I am trying to use REST as much as possible. When is it acceptable to create your own route names?
I generally feel that for standard CRUD actions REST can used but for additional actions you need to create your own route names?
What does everyone else do?
MickBee left a reply on Testing That A Guzzle Call Is Made In An Event Listener.
I'm thinking about this a bit differently now. I am doing it in two ways:
1, test that the event listener is fired. 2, test the Guzzle post response separately.
MickBee started a new conversation Testing That A Guzzle Call Is Made In An Event Listener.
I have an event listener that fires when a new model is created.
In this listener, a Guzzle POST is made (internal API which returns JSON).
How can I confirm in a test, that this call is being made and getting the correct response?
The Editor component does the editing:
I agree, it is difficult because there are many ways to do it, I think it is easier to do the editing on a separate page (or modal).
I can't really see what the problem is but this is how I have achieved this:
In database.php, make sure your have the database connection defined:
'mysqlProductsDB' => [ 'driver' => 'mysql', 'host' => env('DB_HOST_PRODUCTS', 'localhost'), 'database' => env('DB_DATABASE_PRODUCTS', 'forge'), 'username' => env('DB_USERNAME_PRODUCTS', 'forge'), 'password' => env('DB_PASSWORD_PRODUCTS', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],
Then in your model. you just need:
protected $connection = 'mysqlProductsDB';
Does that not work?
"Can the existing API handle authentication for you and then make all API calls to the new Lumen API?"
The existing application is not an API, it is a full Laravel application, so yes it can handle the auth.
"If you don't need the users to interact with the new Lumen API, you can get away with configuring the new Lumen API so that it only accepts calls from your current api"
Users do not interact with the API, only the application does.
So, yes, configuring the Lumen API, to only accept calls from authenticated users sounds perfect. Where do I start with that?
Yes @salmon we have an existing Laravel web application which users log into.
We are now developing a Lumen api, the same set of users will use the api.
I am just looking at securing me new API, it is internal, so we are just using a token in the headers.
I was reading this: http://www.php-dev-zone.com/2018/02/lumen-rest-api-authentication.html
This suggests that the API has access to a users table, is that correct? Should it have its own users table? Or connect to the one belonging to the application?
It looks like they are working, Lumen just doesn't have the
I just noticed that API Resources (https://laravel.com/docs/5.6/eloquent-resources) are not in Lumen. I would have thought that this is the place where they would have been needed most (instead of using Fractal)?
How is everyone else transforming the data, in their Lumen APIs?
Yes, that has sorted it. If anyone else gets this, you need to set the default configuration file on the PHP->Test Frameworks page.
@tykus you are a genius, yes phpUnit.xml is used when I run from the command line.
I think that this means that my configuration is wrong in PHPStorm (this is where I am executing the tests from).
@tykus do you have a database.php file or a config directory?
Thanks @tykus, I appreciate your help.
Still doing the same, I now have this:
<php> <env name="APP_ENV" value="testing"/> <env name="CACHE_DRIVER" value="array"/> <env name="QUEUE_DRIVER" value="sync"/> <env name="DB_CONNECTION" value="testing" /> </php>
I am wondering how do to this with Lumen because there is no database.php?
<env name="APP_ENV" value="testing"/> <env name="CACHE_DRIVER" value="array"/> <env name="QUEUE_DRIVER" value="sync"/> <env name="DB_CONNECTION" value="database.sqlite" /> <env name="DB_DATABASE" value=":memory:" />