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

[Bug] Can't run the tests according to documentation #441

Open
Dirst opened this issue May 24, 2024 · 3 comments
Open

[Bug] Can't run the tests according to documentation #441

Dirst opened this issue May 24, 2024 · 3 comments
Labels
Question Further information is requested Tests Update tests or testing tools

Comments

@Dirst
Copy link

Dirst commented May 24, 2024

Hello, the tests are not working though I did everything according to readme.

I have symfony app.

My worker.test.php

require dirname(__DIR__) . '/vendor/autoload.php';

use App\ProductImportProcess\App\Activity\ProductImportFlowActivity;
use App\ProductImportProcess\App\Workflow\ProductImportWorkflow;
use RoadRunner\VersionChecker\Version\Installed;
use RoadRunner\VersionChecker\VersionChecker;
use Temporal\Testing\WorkerFactory;
use Temporal\Worker\Transport\RoadRunner;
use Temporal\Worker\Transport\RoadRunnerVersionChecker;

$factory = WorkerFactory::create();
$worker = $factory->newWorker();

/**
 * @TODO Сделать добавление автоматическим.
 */
$worker->registerWorkflowTypes(ProductImportWorkflow::class);
$worker->registerActivity(ProductImportFlowActivity::class);
//$worker->registerActivity(FetchProductTemplateActivity::class);
$factory->run(
    RoadRunner::create(
        versionChecker: new RoadRunnerVersionChecker(
            checker: new VersionChecker(
                installedVersion: new Installed(executablePath: 'rr')
            )
        )
    )
);

My tests/.rr.test.yaml

version: "3"

rpc:
    listen: tcp://127.0.0.1:6001

server:
    command: "php /srv/app/tests/worker.test.php"

kv:
    test:
        driver: memory
        config:
            interval: 10

My tests bootstrap.php

use Symfony\Component\Dotenv\Dotenv;
use Temporal\Testing\Environment;

require dirname(__DIR__) . '/vendor/autoload.php';

if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) {
    require dirname(__DIR__) . '/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
    (new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
}

if ($_SERVER['APP_DEBUG']) {
    umask(0);
}

$environment = Environment::create();

$environment->startTemporalTestServer();
$environment->startRoadRunner('tests/rr serve -c .rr.test.yaml -w tests');

register_shutdown_function(fn () => $environment->stop());

My test

namespace App\Tests\New\Functional\Temporal;

use App\ProductImportProcess\App\Workflow\ProductImportWorkflow;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
use Temporal\Client\GRPC\ServiceClient;
use Temporal\Client\WorkflowClient;
use Temporal\Testing\ActivityMocker;

class ProductImportWorkflowTest extends TestCase
{
    private WorkflowClient $workflowClient;
    private ActivityMocker $activityMocks;

    protected function setUp(): void
    {
        $this->workflowClient = new WorkflowClient(ServiceClient::create(getenv('TEMPORAL_ADDRESS')));
        $this->activityMocks = new ActivityMocker();

        parent::setUp();
    }

    protected function tearDown(): void
    {
        $this->activityMocks->clear();
        parent::tearDown();
    }

    public function testWorkflow(): void
    {
        $this->activityMocks->expectCompletion('ProductImportFlowActivity.assertCategoryAssigned', 'world');
        $workflow = $this->workflowClient->newWorkflowStub(ProductImportWorkflow::class);
        $run = $this->workflowClient->start($workflow, Uuid::uuid4());

        $this->assertSame('world', $run->getResult('string'));
    }
}

I run my test with php unit and getting this - it just hangs
image

@Dirst Dirst added the Bug Something isn't working label May 24, 2024
@roxblnfk
Copy link
Collaborator

@roxblnfk
Copy link
Collaborator

roxblnfk commented May 24, 2024

My tests/.rr.test.yaml

There is no temporal section in config

@roxblnfk roxblnfk added Question Further information is requested Tests Update tests or testing tools and removed Bug Something isn't working labels May 24, 2024
@Dirst
Copy link
Author

Dirst commented May 24, 2024

Thanks, this is working now, may it is worth to add this information in Readme for testing framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested Tests Update tests or testing tools
Projects
None yet
Development

No branches or pull requests

2 participants