Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Prestashop Flashlight to launch tests #136

Closed
Maus3rSR opened this issue Oct 7, 2024 · 5 comments
Closed

Using Prestashop Flashlight to launch tests #136

Maus3rSR opened this issue Oct 7, 2024 · 5 comments
Assignees

Comments

@Maus3rSR
Copy link

Maus3rSR commented Oct 7, 2024

Hello

Thank you for first awesome docker image that let us able to run an instance of Prestashop in seconds and install our modules for development purposes.

I would also like to use this image to launch my Integration test. However how can I achieve this goal as the Prestashop code source zip used in the image is a production build and does not contain any testing?

I like to practice TDD, DI, IoC etc. And I really enjoy developing 90% of my module without having to test each time by launching the browser, going to admin, login, goto thing, etc.

I show you the simple thing I try to achieve:

My docker compose

name: $MODULE
services:
  prestashop:
    image: prestashop/prestashop-flashlight:latest
    container_name: $MODULE-ps
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      MODULE_NAME: $MODULE
      PS_DOMAIN: localhost:8000
      INIT_SCRIPTS_DIR: /tmp/init-scripts
    ports:
      - 8000:80
    volumes:
      - ./scripts:/tmp/init-scripts:ro
      - type: bind
        source: ../modules/$MODULE
        target: /var/www/html/modules/$MODULE

  mysql:
    image: mariadb:lts
    container_name: $MODULE-db
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect"]
      interval: 10s
      timeout: 20s
      retries: 5
    environment:
      - MYSQL_USER=prestashop
      - MYSQL_PASSWORD=prestashop
      - MYSQL_ROOT_PASSWORD=prestashop
      - MYSQL_PORT=3306
      - MYSQL_DATABASE=prestashop

in modules/gtrmanager/composer.json

"gtrmanager:test:unit": "docker exec gtrmanager-ps /usr/bin/phpunit -c modules/gtrmanager/tests/Unit/phpunit.xml",
"gtrmanager:test:integration": "docker exec gtrmanager-ps /usr/bin/phpunit -c modules/gtrmanager/tests/Integration/phpunit.xml"

In modules/gtrmanager/tests/Integration/phpunit.xml and bootstrap.php

<phpunit backupGlobals="false" colors="true" bootstrap="bootstrap.php" cacheDirectory=".phpunit.cache" processIsolation="true">
    <php>
        <env name="KERNEL_CLASS" value="AppKernel" />
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
    </php>
    <testsuites>
        <testsuite name="Integration">
            <directory>.</directory>
        </testsuite>
    </testsuites>
    <source>
        <include>
            <directory>../../src</directory>
        </include>
    </source>
</phpunit>
<?php

define('_PS_IN_TEST_', true);
define('_PS_ROOT_DIR_', dirname(__DIR__, 4));
define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/');

require_once _PS_ROOT_DIR_ . '/admin-dev/bootstrap.php';
require_once _PS_MODULE_DIR_ . '/gtrmanager/vendor/autoload.php';

And my test file

<?php

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\Response;


/**
 * @testdox Configuration page
 */
class ConfigurationTest extends WebTestCase
{
    protected KernelBrowser $client;
    protected Router $router;

    protected function setUp(): void
    {
        parent::setUp();
        $this->client = self::createClient();
        $this->router = self::$kernel->getContainer()->get('router');
    }

    /**
     * @test
     * @testdox should be displayed
     */
    public function shouldDisplayConfigurationPage(): void
    {
        $url = $this->router->generate('gtrmanager_configuration');
        $this->client->request('GET', $url);
        $response = $this->client->getResponse();

        $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
    }
}

Im getting hard times running this simple code because when running the test Im going into the test context and Prestashop manage to load test config, using test_databasename, etc. However all these things are missing in a production sourcecode.

How can I achieve that?

@Maus3rSR
Copy link
Author

Maus3rSR commented Oct 7, 2024

Mh, I think you will suggest me to use the Prestashop sourcecode like this example:
https://github.com/PrestaShop/prestashop-flashlight/tree/main/examples/develop-prestashop

However I do not understand why flashlight install phpunit, but use Prestashop production codesource.

When I read the doc, if you want to test and develop with Prestashop, you might use docker image or PS flashlight. But how can you test Prestashop without the whole test env set by Prestashop if the image use production code source.

@jokesterfr
Copy link
Contributor

Flashlight install phpunit, so you can run this in your CI env easily.
Here is an example: https://github.com/PrestaShopCorp/ps_eventbus/blob/main/.github/workflows/quality-check.yml

Any question?

@Maus3rSR
Copy link
Author

Maus3rSR commented Oct 9, 2024

Im able to run phpunit, that's not my issue.

My issue is to run integration test of my module (you can see above). It will run:

  • TEST env mode
  • From that Symfony will try to load the config_test.yml
  • config_test.yml exist, however all the tests dependencies required by the config_test.yml does not exist, composer.json for creating test_database also, etc. That's the point.

@jokesterfr jokesterfr self-assigned this Oct 18, 2024
@jokesterfr
Copy link
Contributor

Hi again,

I won't help you building up your own tests, please tell me what you don't understand using PrestaShop Flashlight, what is does not do for you, how it could help.

I'm sorry I did not understood your needs right now.

@jokesterfr
Copy link
Contributor

jokesterfr commented Oct 18, 2024

If you are looking to directly test PrestaShop sources, this is a WIP: #96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants