Skip to content

Commit

Permalink
feat: operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferror committed May 4, 2024
1 parent 4cd77b3 commit 774f713
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 1 deletion.
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>

<php>
Expand Down
141 changes: 140 additions & 1 deletion tests/Integration/DumpSpecificationConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public function testExecuteClass(): void
$this->assertEquals($expectedDisplay, $display);
}

public function testExecuteYaml(): void
public function testExecuteYamlV2(): void
{
if ($this->isV3()) {
$this->markTestSkipped('Skipping schema V2 test on V3 variable');
}

$kernel = self::bootKernel();
$application = new Application($kernel);

Expand Down Expand Up @@ -195,6 +199,141 @@ public function testExecuteYaml(): void
}
}

public function testExecuteYamlV3(): void
{
if (false === $this->isV3()) {
$this->markTestSkipped('Skipping schema V3 test on V2 variable');
}

$kernel = self::bootKernel();
$application = new Application($kernel);

$command = $application->find('ferror:asyncapi:dump');
$commandTester = new CommandTester($command);
$commandTester->execute(['format' => 'yaml']);

$commandTester->assertCommandIsSuccessful();

$display = $commandTester->getDisplay();

$expectedDisplay = <<<YAML
asyncapi: 3.0.0
info:
title: 'Service Example API'
version: 1.2.3
description: 'This service is in charge of processing user signups'
channels:
user_signed_up:
messages:
UserSignedUp:
\$ref: '#/components/messages/UserSignedUp'
payment_executed:
messages:
PaymentExecuted:
\$ref: '#/components/messages/PaymentExecuted'
product.created:
messages:
ProductCreated:
\$ref: '#/components/messages/ProductCreated'
components:
messages:
UserSignedUp:
payload:
type: object
properties:
name:
type: string
description: 'Name of the user'
format: string
example: John
email:
type: string
description: 'Email of the user'
format: email
example: [email protected]
age:
type: integer
description: 'Age of the user'
format: int32
example: '18'
isCitizen:
type: boolean
description: 'Is user a citizen'
format: boolean
example: 'true'
required:
- name
- email
- age
- isCitizen
PaymentExecuted:
payload:
type: object
properties:
amount:
type: number
createdAt:
type: string
required:
- amount
- createdAt
ProductCreated:
payload:
type: object
properties:
id:
type: integer
amount:
type: number
currency:
type: string
isPaid:
type: boolean
createdAt:
type: string
format: date-time
week:
type: integer
payment:
type: string
products:
type: string
tags:
type: string
required:
- id
- amount
- currency
- isPaid
- createdAt
- week
- payment
- products
- tags
servers:
production:
protocol: amqp
description: 'This is production broker.'
host: broker.mycompany.com
staging:
protocol: amqp
description: 'This is staging broker.'
host: broker.mycompany.com
YAML;

$this->assertEquals($expectedDisplay, $display);

mkdir(dirname(__DIR__) . '/../var/' . $this->getSchemaVersion());

$content = file_put_contents(dirname(__DIR__) . '/../var/' . $this->getSchemaVersion() . '/asyncapi.yaml', $display);

if (false === $content) {
throw new RuntimeException('Schema file was not save');
}
}

public function testExecuteJson(): void
{
$kernel = self::bootKernel();
Expand Down

0 comments on commit 774f713

Please sign in to comment.