# |
May 15th 2021, 14:20 |
martin |
```bin/cake worker --processor=test Exception: Processor was not found. processorName: "Cake\Queue\Queue\Processor609fc922dca73" In [/var/www/vendor/enqueue/enqueue/ArrayProcessorRegistry.php, line 33]``` still trying to use a proccesor that is unknown and not the name that I did give |
# |
May 15th 2021, 14:18 |
martin |
I can give a processorname with --processor but what would be the right name? |
# |
May 15th 2021, 14:14 |
martin |
@admad but that issue is fixed? or not merged yet? |
# |
May 15th 2021, 14:05 |
admad |
@martin https://github.com/cakephp/queue/issues/50 |
# |
May 15th 2021, 13:16 |
slackebot |
/var/www/vendor/cakephp/cakephp/src/Console/CommandRunner.php:335 - /var/www/vendor/cakephp/cakephp/src/Console/CommandRunner.php:171 - /var/www/bin/cake.php:12``` is this a issue in queue? I have nothing done with the Processor |
# |
May 15th 2021, 13:16 |
slackebot |
/var/www/vendor/enqueue/enqueue/Consumption/QueueConsumer.php:197 - call_user_func - [internal], line ??- /var/www/vendor/enqueue/redis/RedisSubscriptionConsumer.php:75 - /var/www/vendor/enqueue/enqueue/Consumption/QueueConsumer.php:264 - /var/www/vendor/enqueue/simple-client/SimpleClient.php:209 - /var/www/vendor/cakephp/queue/src/Command/WorkerCommand.php:147 - /var/www/vendor/cakephp/cakephp/src/Console/BaseCommand.php:179 - |
# |
May 15th 2021, 13:16 |
martin |
Hi, I've installed cakephp/queue, installed redis, created a job, it works a little bit every xxx minutes it gives the error: ```2021-05-15 00:06:40 Error: [LogicException] Processor was not found. processorName: "Cake\Queue\Queue\Processor609f0e301d4d5" in /var/www/vendor/enqueue/enqueue/ArrayProcessorRegistry.php on line 33 Stack Trace: - /var/www/vendor/enqueue/enqueue/Client/DelegateProcessor.php:38 - |
# |
May 14th 2021, 19:41 |
kevin.pfeifer |
but as far as i know both should be present in cake3 |
# |
May 14th 2021, 19:38 |
kevin.pfeifer |
could be that you would have to use slightly different functions if they are not present in cake3 yet |
# |
May 14th 2021, 19:37 |
etibor |
is this could work in cake3? |
# |
May 14th 2021, 19:36 |
etibor |
@kevin.pfeifer thank you soo much for your help |
# |
May 14th 2021, 19:20 |
kevin.pfeifer |
i would `$query->orderDesc('id')->limit(1)` |
# |
May 14th 2021, 19:13 |
etibor |
what is the best way to get the highest element in a group? i tried with select(['id'=>'MAX(id)'])->group(['document_id']) |
# |
May 14th 2021, 19:12 |
etibor |
hello everyone |
# |
May 14th 2021, 16:46 |
matthttam |
I'm off to lunch but i'll be back |
# |
May 14th 2021, 16:46 |
matthttam |
I'm just so confused on how to make something so simple but so complicated at the same time work.... |
# |
May 14th 2021, 16:45 |
matthttam |
Yea. I don't really care that the endpoint model in question is called or not. I just need it to not throw an error when loading the model and getting locations. I don't care to simulate what the API _should_ return... that is fine. Basically I wish I could do a fixture but without a database table.... one that pretends to give you a query and ultimately outputs an array I guess |
# |
May 14th 2021, 16:37 |
slackebot |
wrong data, that means that your test object wasn't (properly) invoked. |
# |
May 14th 2021, 16:37 |
ndm |
Both can be fine, mocks with expectations will give you more failure details so to speak, as they will check that your test actually used your test objects. Now if your test object returns data that is clearly different to what the real API would return, and you test for that specific data in the response, then the additional expectation of the test object being invoked would kinda be redundant, as you'd know that if you get the |
# |
May 14th 2021, 16:30 |
slackebot |
make those two things happen? |
# |
May 14th 2021, 16:30 |
matthttam |
All I know is that I want the code in the controller action: ```$this->loadModel('Freshservice.Locations', 'Endpoint'); $locations = $this->Locations->find('all')->toArray(); $this->set(compact('locations'));``` when ran by the test to work. So in my mind, I need the loadModel to not fail. And the $this->Locations->find('all')->toArray(); to create a predefined array of information. Would you recommend a mock or a stub to |
# |
May 14th 2021, 16:29 |
ndm |
As mentioned, it doesn't make much of a difference in your specific case, given how simple the code is. |
# |
May 14th 2021, 16:25 |
slackebot |
verifying behavior. |
# |
May 14th 2021, 16:25 |
ndm |
@matthttam It depends on where/how you use the mock. Generally a mock is ment to test whether it is interacted with in the way you expect it to, whether this is required/helpful/etc, depends. A stub will not cause a failure when the configured methods are not being invoked, or when they're invoked the wrong way. That information might be helpful to figure why things go wrong, even if your situation doesn't technically require |
# |
May 14th 2021, 15:52 |
matthttam |
Again, very new to this and I feel this is quite advanced. So my perceptions of how these are used could be very wrong. I've just been reading the PHPUnit docs |
# |
May 14th 2021, 15:51 |
matthttam |
I'll check that. But, it seems to me that Mock is meant to test the class itself sort of. But I am not testing that Locations->find() returns a query... I'm just trying to test that getting 'assets/test' loads properly. So, does it not make sense to just stub the "Endpoint" model to make that variable populate properly in the controller during the test? |
# |
May 14th 2021, 15:46 |
ndm |
Making your code shorter isn't a good reason, whether to use a stub or a mock should depend on what is appropriate/required from a purely technical point of view. `$this` in a closure will always refer to the outer scope. Again, check your error logs for information on what exactly is causing that 500 error. |
# |
May 14th 2021, 15:40 |
matthttam |
And, I can't use the EventManager::instance() for some reason... the code inside just throws a 500 error. I'm guessing because "this" isn't the test class anymore but rather the eventmanager class and I don't know how to fix this honestly |
# |
May 14th 2021, 15:39 |
slackebot |
presumably queryStub would have methods for returning an array The problem is I'm still stuck on: ```InvalidArgumentException: Unknown repository type "Endpoint". Make sure you register a type before trying to use it.``` |
# |
May 14th 2021, 15:39 |
matthttam |
I'm leaning to making a stub of each element to make this work and it may be because I don't completely understand _how_ to make a simple test run when I'm using this plugin.... I guess the "why" is so that _if_ I can make the code: ```$locator = \Cake\Datasource\FactoryLocator::get('Endpoint'); $locator->set('Freshservice.Locations', $locationsStub);``` work then I can just do a ->method('find')->willReturn($queryStub) Then |
# |
May 14th 2021, 15:36 |
ndm |
@matthttam The answer probably lies in the "_why_" you'd want to do that. It doesn't make much of a difference, stubs are just more lenient mocks, as they are ment to not define expectations. |
# |
May 14th 2021, 15:20 |
kevin.pfeifer |
@greenmanspirit hmm, seems strange. Got anything particular in your logs? It should work the same way from B => C if it already works from C => B |
# |
May 14th 2021, 15:17 |
greenmanspirit |
@kevin.pfeifer I have $this->belongsToMany('B'); in C and $this->belongsToMany('C'); in B |
# |
May 14th 2021, 15:16 |
matthttam |
@ndm What if.... What if I stubbed the LocationsEndpoint::class. Then mocked the query that is returned? |
# |
May 14th 2021, 15:13 |
kevin.pfeifer |
@greenmanspirit and you are sure you configured the HABTM Connection in your Table correctly on the B Model side? |
# |
May 14th 2021, 15:12 |
greenmanspirit |
@kevin.pfeifer Yes, that works just fine. |
# |
May 14th 2021, 15:10 |
slackebot |
building custom locators (if you can't use DI yet), then you could wrap things in custom services that have a cleaner, easier to mock API. As far as the error is concerned, check your error logs for more details (`/logs/`), 500 indicates that an exception was thrown. |
# |
May 14th 2021, 15:10 |
slackebot |
->getMockBuilder(\Muffin\Webservice\Datasource\Query::class) ->onlyMethods(['toArray']) ->getMock(); $queryMock ->expects($this->once()) ->method('toArray') ->willReturn([ 'some test data' ]); $locationsMock ->expects($this->once()) ->method('find') ->willReturn($queryMock);``` With that amount of mocking required, especially mocking 3rd party code, you may want to consider learning about |
# |
May 14th 2021, 15:10 |
ndm |
@matthttam Yes, expectations define what you expect with your mocks to happen, for example `find` being invoked and returning an object that you've defined, one that provides a `toArray()` method that returns your test data. That's PhpUnit basics, so I'd highly recommended that you make yourself familiar with it first: https://phpunit.readthedocs.io/en/9.5/test-doubles.html Quick and dirty example: ```$queryMock = $this |
# |
May 14th 2021, 15:08 |
kevin.pfeifer |
but when you delete an entry from model C does it remove the connection data between C and B for that? |
# |
May 14th 2021, 14:59 |
greenmanspirit |
delete when B is deleted. Any help will be appreciated. |