Log message #4265134

# At Username Text
# Jun 11th 2021, 05:15 paolo.bragagni $this->searchManager() ->add('numero_scaffale', 'Search.Value', [ 'fields' => ['numero_scaffale'],
# Jun 10th 2021, 22:17 jpramirez Ah O.K. so this is not a unit test, because you are not testing your model domain, but the interaction with the outer world from your app's perspective. I am saying this only to remind you to write unit tests, and not only some let's call them end to end tests. When interacting with an API, your only chance is to mock the contract with your API. Does this make sense to you?
# Jun 10th 2021, 22:08 tyler.adam.lazenby The the refresh token you save to prevent you from doing that
# Jun 10th 2021, 22:08 tyler.adam.lazenby Its because Google OAuth only allows you to refresh a token 5 times within a given period of time
# Jun 10th 2021, 22:07 jpramirez Can you re-explain your question @tyler.adam.lazenby ? A unit test that works five time only is a cheap one :smiling_face_with_tear:
# Jun 10th 2021, 21:36 tyler.adam.lazenby Really complicated question here. I am testing with oAuth connections, and unit testing the token with my test database works 5 times until the max number of refresh tokens allowed for a client are met. How would you go about making sure that once a refresh token is saved, that the fixture itelf accepts that?
# Jun 10th 2021, 18:44 tyler.adam.lazenby I mean, I get it the route collection ensures have the collection ready to go
# Jun 10th 2021, 18:43 admad Smart :)
# Jun 10th 2021, 18:42 tyler.adam.lazenby that is what I got it from :P
# Jun 10th 2021, 18:42 admad That's essentially what's used to parse the current request url too :)
# Jun 10th 2021, 18:38 greg138 In 3.x, at least, it seems that `loadRoutes` is called by any router function that might need them, like `url`.
# Jun 10th 2021, 18:38 kevin.pfeifer thats cool, didn’t know that :thinking_face:
# Jun 10th 2021, 18:36 kevin.pfeifer routes are definitely not loaded by default
# Jun 10th 2021, 18:35 tyler.adam.lazenby ```public function sendEmail() { $this->Authorization->skipAuthorization(); $referrer = $this->request->referer(); $params = Router::getRouteCollection()->parse($referrer); return $this->response->withDisabledCache() ->withType('application/json') ->withStringBody(json_encode([ 'url' => $referrer, 'params' => $params ])); }```
# Jun 10th 2021, 18:34 kevin.pfeifer `Cake\TestSuite\TestCase` yes
# Jun 10th 2021, 18:34 tyler.adam.lazenby but I think I just figured out a way
# Jun 10th 2021, 18:34 tyler.adam.lazenby Just the refering url
# Jun 10th 2021, 18:33 greg138 I've never needed to do this. Are you extending Cake's `TestCase` class?
# Jun 10th 2021, 18:29 kevin.pfeifer if so then you have everything in this array ```$params = $this->getRequest()->getAttribute('params');```
# Jun 10th 2021, 18:28 kevin.pfeifer do you have a request object where you want to do that?
# Jun 10th 2021, 18:22 tyler.adam.lazenby I know you can reverse an array into a string, but I can't seem to figure out how to take the referer url and make it something my system can use
# Jun 10th 2021, 18:22 tyler.adam.lazenby Is there a method for taking apart a url and seperating it into its Router elements?
# Jun 10th 2021, 18:06 tyler.adam.lazenby yay! finally got it to spit out the referer
# Jun 10th 2021, 17:55 tyler.adam.lazenby thanks
# Jun 10th 2021, 17:55 tyler.adam.lazenby I was looking for something like that
# Jun 10th 2021, 17:53 kevin.pfeifer https://book.cakephp.org/4/en/development/testing.html#loading-routes-in-tests
# Jun 10th 2021, 17:53 kevin.pfeifer ```public function setUp(): void { parent::setUp(); $this->loadRoutes(); }```
# Jun 10th 2021, 17:53 kevin.pfeifer you need to load them in your setup function
# Jun 10th 2021, 17:53 kevin.pfeifer routes are not loaded automatically in tests
# Jun 10th 2021, 17:51 tyler.adam.lazenby ```public function testSendEmail(): void { $referral_url = Router::url([ 'controller' => 'Contacts', 'action' => 'view', 1 ], true); $headers = ['referrer' => $referral_url]; $this->configRequest([ 'headers' => $headers ]); $this->get('contact/send-email'); $data = json_decode($this->_getBodyAsString()); dd($data); }```
# Jun 10th 2021, 17:51 tyler.adam.lazenby Cake\Routing\Exception\MissingRouteException : A route matching "array ( 'controller' => 'Contacts', 'action' => 'view', 0 => 1, 'plugin' => NULL, '_ext' => NULL, )" could not be found.
# Jun 10th 2021, 17:51 tyler.adam.lazenby Well that is all well and good, until you have this error because phpunit doesn't build the router
# Jun 10th 2021, 17:48 kevin.pfeifer didn’t read slack before posting :,)
# Jun 10th 2021, 17:48 kevin.pfeifer well
# Jun 10th 2021, 17:48 kevin.pfeifer ``` $this->configRequest([ 'headers' => ['Accept' => 'application/json'] ]);```
# Jun 10th 2021, 17:45 tyler.adam.lazenby Oof thanks
# Jun 10th 2021, 17:45 greg138 https://book.cakephp.org/3/en/development/testing.html#setting-up-the-request
# Jun 10th 2021, 17:44 tyler.adam.lazenby Hetting the appropriate header with phpunit?
# Jun 10th 2021, 17:44 greg138 That's just a matter of setting the appropriate header in your simulated call to `send-email`.
# Jun 10th 2021, 17:44 tyler.adam.lazenby exactly
# Jun 10th 2021, 17:44 kevin.pfeifer so you check the url / referrer of that ajax call in your controller function?