Skip to content

Commit

Permalink
Update from to node_id and update test suite (#37)
Browse files Browse the repository at this point in the history
* Update to test suite

* ci fixes

* Update phpunit.xml

---------

Co-authored-by: Matthew Nessworthy <matthew.nessworthy@gmail.com>
  • Loading branch information
sjmarve and matthewnessworthy authored May 8, 2023
1 parent f7baff0 commit 02ca59a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 44 deletions.
58 changes: 31 additions & 27 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="RIMU Service Bus Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="RIMU Service Bus Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
</phpunit>
1 change: 0 additions & 1 deletion src/ServiceBusChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function send($notifiable, Notification $notification)
'json' => [$params],
]
);

if (!in_array($eventType, $dontReport)) {
Log::debug(
"$eventType service bus notification",
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceBusEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function getParams(): array
return [
'events' => [$this->eventType],
'reference' => $this->reference,
'from' => $this->config['from'],
'from' => $this->config['node_id'],
'created_at' => $this->createdAt->toISOString(),
'version' => $this->config['version'],
'route' => $this->route,
Expand Down
9 changes: 7 additions & 2 deletions tests/ServiceBusChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ServiceBusChannelTest extends TestCase
public function testShouldCreateServiceBusChannelInstance()
{
$this->mockAll();
$serviceChannel = new ServiceBusChannel();
$serviceChannel = new ServiceBusChannel(config_v2());

$this->assertNotNull($serviceChannel);
}
Expand All @@ -38,6 +38,11 @@ public function testShouldThrowRequestExceptionOnSendEvent()
$this->expectException(CouldNotSendNotification::class);

$this->mockAll();
Cache::shouldReceive('rememberForever')
->andReturn(true);
Cache::shouldReceive('forget')
->andReturn(true);

$serviceChannel = new ServiceBusChannel();

$serviceChannel->send(new AnonymousNotifiable(), new TestNotification());
Expand All @@ -50,7 +55,7 @@ private function mockAll()
{
Cache::shouldReceive('get')
->once()
->with((new ServiceBusChannel())->generateTokenKey())
->with((new ServiceBusChannel(config_v2()))->generateTokenKey())
->andReturn('value');

Log::shouldReceive('debug')
Expand Down
25 changes: 13 additions & 12 deletions tests/ServiceBusEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class ServiceBusEventTest extends TestCase
{
public function testShouldCreateServiceBusEventInstance()
{
$serviceBus = new ServiceBusEvent('test');
$serviceBus = new ServiceBusEvent('test', config_v2());

$this->assertEquals('test', $serviceBus->getEventType());
}

public function testShouldCreateServiceBusEventInstanceViaStaticCall()
{
$serviceBus = ServiceBusEvent::create('test');
$serviceBus = ServiceBusEvent::create('test', config_v2());

$this->assertEquals('test', $serviceBus->getEventType());
}
Expand Down Expand Up @@ -55,7 +55,7 @@ public function testShouldAllocateAttributesToServiceBusObject()
'phone' => '0123456789',
];

$serviceBus = ServiceBusEvent::create('test')
$serviceBus = ServiceBusEvent::create('test', config_v2())
->withAction('other', uniqid())
->withCulture('en')
->withReference(uniqid())
Expand All @@ -71,7 +71,7 @@ public function testShouldAllocateAttributesToServiceBusObject()
$this->assertArrayHasKey('resource', $serviceBusData['payload']);
$this->assertContains('test', $serviceBusData['events']);

$this->assertEquals([$resource], $serviceBusData['payload']['resource']);
$this->assertEquals($resource, $serviceBusData['payload']['resource']);
}

/**
Expand All @@ -88,7 +88,7 @@ public function testShouldAllocateAttributesToServiceBusObjectWithPayload()
],
];

$serviceBus = ServiceBusEvent::create('test')
$serviceBus = ServiceBusEvent::create('test', config_v2())
->withAction('other', uniqid())
->withCulture('en')
->withReference(uniqid())
Expand All @@ -112,21 +112,22 @@ public function testShouldAllocateAttributesToServiceBusObjectWithPayload()
*/
public function testShouldReturnCorrectEventForSpecificVersion()
{
$version2Structure = [
'from' => '576192a7-8719-4dc0-a058-76f66973af0a',
'version' => '2.0.0',
];

$serviceBusVersion1 = ServiceBusEvent::create('test')
$serviceBusVersion1 = ServiceBusEvent::create('test', config_v1())
->withAction('other', uniqid())
->withCulture('en')
->withReference(uniqid())
->withRoute('api')
->withPayload([
'listing' => [],
])
->createdAt(Carbon::now());

$serviceBusVersion2 = ServiceBusEvent::create('test', $version2Structure)
$serviceBusVersion2 = ServiceBusEvent::create('test', config_v2())
->withReference(uniqid())
->withRoute('api')
->withPayload([
'listing' => [],
])
->createdAt(Carbon::now());

$serviceBusDataVersion1 = $serviceBusVersion1->getParams();
Expand Down
41 changes: 40 additions & 1 deletion tests/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@
*/
function config($key = null, $default = null)
{
return 'true';
return config_v1();
}
}

if (!function_exists('config_v1')) {
/**
* Mocked Laravel helper config values for v1 of eventbus.
*
* @return array
*/
function config_v1()
{
return [
'enabled' => true,
'venture_config_id' => '123456789',
'username' => 'username',
'password' => 'password',
'version' => '1.0.0',
'culture' => 'en_GB',
'endpoint' => 'https://bus.staging.ritdu.tech/v1/',
];
}
}

if (!function_exists('config_v2')) {
/**
* Mocked Laravel helper config values for v2 of the eventbus.
*
* @return array
*/
function config_v2()
{
return [
'enabled' => true,
'node_id' => '123456789',
'username' => 'username',
'password' => 'password',
'version' => '2.0.0',
'endpoint' => 'https://bus.staging.ritdu.tech/v1/',
];
}
}

0 comments on commit 02ca59a

Please sign in to comment.