How to test the extension classes ?

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
dheeraj
Posts: 26
Joined: 02 Jan 2021, 08:47

How to test the extension classes ?

Post by dheeraj » 15 Jan 2021, 09:08

Laravel : 8.12
Aimeos : 2020.10
PHP Version : 7.4.13
Environment : Windows


I have created Item, Manager, JQAdm Panel, Frontend Controller and JSONAPI client classes for my new data domain.
I created test classes for all of these in their own test folders as in the directory structure of aimeos extension.
I saw in the aimeos documentation that in order to test my classes i need to first checkout in the aimeos-core repository and copy my custom extension folder there and configure test database. This way of testing seems to be an overkill.
Is there any other good way to test the classes in the custom aimeos extension inside the same project ?

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to test the extension classes ?

Post by aimeos » 15 Jan 2021, 12:29

Yes, it's possible if you run

Code: Select all

php artisan aimeos:setup unittest unittest
to create the unittest data and call phpunit with the required parameters, e.g.

Code: Select all

vendor/bin/phpunit --bootstrap=vendor/autoload.php -c ext/ai-admin-jqadm/lib/custom/tests/phpunit.xml
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
dheeraj
Posts: 26
Joined: 02 Jan 2021, 08:47

Re: How to test the extension classes ?

Post by dheeraj » 16 Jan 2021, 06:51

The phpunit unit command is displaying an error. I ran the following command -

Code: Select all

vendor/bin/phpunit --bootstrap=./vendor/autoload.php -c ./ext/ext-pincode/lib/custom/tests/phpunit.xml
It is running my test cases but the classes are not recognized and errors are being displayed.
Screenshot 2021-01-16 120805.png
Screenshot 2021-01-16 120805.png (63.18 KiB) Viewed 3681 times
I also tried to run the following phpunit command -

Code: Select all

vendor/bin/phpunit --bootstrap=./ext/ext-pincode/vendor/autoload.php -c ./ext/ext-pincode/lib/custom/tests/phpunit.xml
and this time only TestHelper class not found is shown in the errors.
Screenshot 2021-01-16 121549.png
Screenshot 2021-01-16 121549.png (110.36 KiB) Viewed 3681 times
Why are the classes not being found in the test cases of extension??

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to test the extension classes ?

Post by aimeos » 17 Jan 2021, 11:51

If your extension isn't installed via composer, you must execute

Code: Select all

composer dump-autoload
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
dheeraj
Posts: 26
Joined: 02 Jan 2021, 08:47

Re: How to test the extension classes ?

Post by dheeraj » 18 Jan 2021, 04:21

Executed

Code: Select all

composer dump-autoload
and still not working!!

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to test the extension classes ?

Post by aimeos » 18 Jan 2021, 17:43

Maybe there's another problem with your custom extension but for the Aimeos standard extensions it works pretty well, e.g.:

Code: Select all

vendor/bin/phpunit --bootstrap=vendor/autoload.php -c ext/ai-admin-jqadm/lib/custom/tests/phpunit.xml
Does this command also works in your installation?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
dheeraj
Posts: 26
Joined: 02 Jan 2021, 08:47

Re: How to test the extension classes ?

Post by dheeraj » 19 Jan 2021, 04:05

aimeos wrote: 18 Jan 2021, 17:43 Maybe there's another problem with your custom extension but for the Aimeos standard extensions it works pretty well, e.g.:

Code: Select all

vendor/bin/phpunit --bootstrap=vendor/autoload.php -c ext/ai-admin-jqadm/lib/custom/tests/phpunit.xml
Does this command also works in your installation?
Yes! this command is working.

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to test the extension classes ?

Post by aimeos » 19 Jan 2021, 08:31

I think, you have to add the path of your new extension to the "classmap" section of your composer.json and run "composer dump-autoload" again because it's unknown to composer if it's not installed via composer.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
dheeraj
Posts: 26
Joined: 02 Jan 2021, 08:47

Re: How to test the extension classes ?

Post by dheeraj » 19 Jan 2021, 11:26

Thanks! Now the test cases are executed.
One last thing, for test cases requiring database access, it is not using the database configuration set in .env file. Do i have to separately configure database for testing and if yes where?

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to test the extension classes ?

Post by aimeos » 20 Jan 2021, 12:54

That's a bit tricky. You can add ./ext/<yourext>/config/resource.php to your extension with:

Code: Select all

<?php
return [
	'db' => [
		'adapter' => config('database.connections.mysql.driver', 'mysql'),
		'host' => config('database.connections.mysql.host', '127.0.0.1'),
		'port' => config('database.connections.mysql.port', '3306'),
		'socket' => config('database.connections.mysql.unix_socket', ''),
		'database' => config('database.connections.mysql.database', 'forge'),
		'username' => config('database.connections.mysql.username', 'forge'),
		'password' => config('database.connections.mysql.password', ''),
		'stmt' => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"],
		'limit' => 3, // maximum number of concurrent database connections
	]
];
but you should remove that file after testing because it will take precedence for your DB settings also in production.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply