# |
May 14th 2021, 14:19 |
matthttam |
@ndm ```1) App\Test\TestCase\Controller\AssetsControllerTest::testTest InvalidArgumentException: Unknown repository type "Endpoint". Make sure you register a type before trying to use it.``` I mocked the webservice like so too... not sure if this is right honestly... ```$locations = $this->getMockForAbstractClass( 'Freshservice\Webservice\LocationsWebservice', array(), 'Locations', false |
# |
May 14th 2021, 14:16 |
matthttam |
I'll try this |
# |
May 14th 2021, 14:16 |
matthttam |
@ndm I am unfortunately currently on 4.0.7. I plan to upgrade soon though. |
# |
May 14th 2021, 14:15 |
ndm |
@matthttam Two suggestions, if you're on CakePHP 4.2+, use DI, container dependencies can be easily mocked (https://book.cakephp.org/4/en/development/dependency-injection.html#mocking-services-in-tests). Alternatively mock the model in the `Endpoint` locator, like: ```$locator = \Cake\Datasource\FactoryLocator::get('Endpoint'); $locator->set('Freshservice.Locations', $yourLocationsMockInstance);``` |
# |
May 14th 2021, 14:15 |
matthttam |
You install the plugin and then specify the host and scheme for the connection in your app_local.php file. Then, you set the API key dynamically based on the user who signs in (or at least that is how my app I am building does it). ```'freshservice' => [ 'host' => 'your_domain.freshservice.com/api/v2/', 'scheme' => 'https', ],``` |
# |
May 14th 2021, 14:13 |
jpramirez |
I see no config folder in your project. Where are the Datasources defined? |
# |
May 14th 2021, 14:08 |
matthttam |
Maybe I need to build a test_app folder like UseMuffin/Webservice does in my plugin? https://github.com/UseMuffin/Webservice/blob/master/tests/test_app/Webservice/StaticWebservice.php |
# |
May 14th 2021, 14:07 |
matthttam |
The thing is... I have a test database and tests that use my database work fine. The Freshservice plugin utilizes https://github.com/UseMuffin/Webservice This is the plugin I am using (and the one I built actually....) https://packagist.org/packages/matt_henry_ops/freshservice |
# |
May 14th 2021, 14:05 |
jpramirez |
@matthttam reading the error you received, I would check that: https://book.cakephp.org/4/en/development/testing.html#test-database-setup Does this helps? |
# |
May 14th 2021, 13:48 |
slackebot |
an actual model... its a model of type "Endpoint".... and I tried mocking the class but even though I could do that it didn't make the test work lol. I'm just at a loss. |
# |
May 14th 2021, 13:48 |
matthttam |
Even loading a fixture from plugins.Freshservice.Locations fails still with an error of ```1) App\Test\TestCase\Controller\AssetsControllerTest::testTest Possibly related to Cake\Datasource\Exception\MissingDatasourceConfigException: "The datasource configuration "test_freshservice" was not found."``` I was hoping the loadModel would use the fixture or something... but it didn't And I don't know how to mock it since it isn't |
# |
May 14th 2021, 13:43 |
matthttam |
Here is an action in my AssetsController file that I made just to try to figure out testing. ``` public function test() { $this->loadModel('Freshservice.Locations', 'Endpoint'); $locations = $this->Locations->find('all')->toArray(); $this->set(compact('locations')); }``` |
# |
May 14th 2021, 13:40 |
matthttam |
I'm really struggling with being able to write tests in cakephp. I'm using a plugin called freshservice that utilizes a web API. I don't want the tests to pull real data obviously so I've been trying to figure out how to either use a mock or a fixture so that the controller tests can succeed with fake data. Nothing I've tried works and I feel a bit out of my element here... |
# |
May 14th 2021, 10:59 |
kevin.pfeifer |
or any special plugins |
# |
May 14th 2021, 10:58 |
kevin.pfeifer |
the fact that it works with new data tells you/us, that there is nothing wrong with your model/table where your connections are being defined Are you use you don't have any custom event listeners which could change the entities in like a `beforeFind` or something like that? |
# |
May 14th 2021, 10:51 |
etibor |
anyway i appreciate your help |
# |
May 14th 2021, 10:00 |
kevin.pfeifer |
no idea :man-shrugging: |
# |
May 14th 2021, 09:41 |
etibor |
@kevin.pfeifer it is with old datas, i deleted the orm caches as well the normal cache |
# |
May 14th 2021, 09:27 |
martin |
oh it is al in RC3 I see :) |
# |
May 14th 2021, 09:26 |
martin |
Building another webservice (UseMuffin/Webservice) ( for cakephp, have already 5 in this project now. Really nice way to communicate with external services from cakephp. Hope the cake 4 version of that will release soon :) |
# |
May 14th 2021, 09:25 |
kevin.pfeifer |
can you reproduce the error with newly created entites or is it just present with "old" data |
# |
May 14th 2021, 09:23 |
etibor |
thats the case |
# |
May 14th 2021, 09:23 |
etibor |
yes its seems |
# |
May 14th 2021, 09:21 |
kevin.pfeifer |
so does it show the correct associated entities but its just missing a field? |
# |
May 14th 2021, 09:16 |
etibor |
debug the query shows for error: ```protected '_errors' => array (size=0) empty``` |
# |
May 14th 2021, 09:15 |
etibor |
no any further fields |
# |
May 14th 2021, 09:15 |
etibor |
debug shows for the associated Model: ```'Documents' => object(App\Model\Entity\Documents)[293] ...``` |
# |
May 14th 2021, 09:14 |
etibor |
its shows the desire values, but does not arrive into cake |
# |
May 14th 2021, 09:13 |
etibor |
thank you @kevin.pfeifer i checked the sql and than manually executed |
# |
May 14th 2021, 09:08 |
kevin.pfeifer |
check the executed SQL queries via DebugKit if everything is in there that you expect |
# |
May 14th 2021, 09:05 |
etibor |
the normal contain does not worked as before so i contained the Documents but the Documents.description does not avaliable i double checked the entity file the description is accessible |
# |
May 14th 2021, 09:04 |
etibor |
a strange thing happened today |
# |
May 14th 2021, 09:04 |
etibor |
hello everyone |
# |
May 13th 2021, 22:26 |
rightscoreanalysis |
ignore that ^ |
# |
May 13th 2021, 22:21 |
rightscoreanalysis |
for example Orders conroller beforefilter $this->Orders->find... |
# |
May 13th 2021, 22:20 |
rightscoreanalysis |
do we not have access to models in beforeFilter |
# |
May 13th 2021, 19:19 |
ndm |
Generally, yes. |
# |
May 13th 2021, 19:15 |
rightscoreanalysis |
if I have a table-less model and I need to load another model, is this acceptable: $myModel = ClassRegistry::init('MyModel'); |
# |
May 13th 2021, 15:16 |
neon1024 |
Ah 4.4 is out! :rollsafe: |
# |
May 13th 2021, 15:16 |
neon1024 |
> cakephp/debug_kit 4.2.0 requires composer/composer ^1.3 |
# |
May 13th 2021, 15:16 |
neon1024 |
Any reason for DebugKit to not use Composer 2? |