Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
The tests is now compatible with latest Laravel version (6.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
phantom committed Sep 27, 2019
1 parent dde4e6a commit fdef9b2
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 59 deletions.
28 changes: 14 additions & 14 deletions tests/IntercomChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace FtwSoft\NotificationChannels\Intercom\Tests;

use GuzzleHttp\Psr7\Request;
use Intercom\IntercomClient;
use Intercom\IntercomMessages;
use Illuminate\Notifications\Notification;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use GuzzleHttp\Exception\BadResponseException;
use FtwSoft\NotificationChannels\Intercom\Exceptions\InvalidArgumentException;
use FtwSoft\NotificationChannels\Intercom\Exceptions\MessageIsNotCompleteException;
use FtwSoft\NotificationChannels\Intercom\Exceptions\RequestException;
use FtwSoft\NotificationChannels\Intercom\IntercomChannel;
use FtwSoft\NotificationChannels\Intercom\IntercomMessage;
use FtwSoft\NotificationChannels\Intercom\Tests\Mocks\TestNotifiable;
use FtwSoft\NotificationChannels\Intercom\Exceptions\RequestException;
use FtwSoft\NotificationChannels\Intercom\Tests\Mocks\TestNotification;
use FtwSoft\NotificationChannels\Intercom\Exceptions\InvalidArgumentException;
use FtwSoft\NotificationChannels\Intercom\Exceptions\MessageIsNotCompleteException;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Psr7\Request;
use Illuminate\Notifications\Notification;
use Intercom\IntercomClient;
use Intercom\IntercomMessages;
use Mockery\Adapter\Phpunit\MockeryTestCase;

class IntercomChannelTest extends MockeryTestCase
{
Expand All @@ -33,7 +33,7 @@ class IntercomChannelTest extends MockeryTestCase
*/
private $channel;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -70,15 +70,15 @@ public function testItCanSendMessage(): void
$this->assertPostConditions();
}

public function testInThrowsAnExceptionWhenNotificationIsNotAnIntercomNotification()
public function testInThrowsAnExceptionWhenNotificationIsNotAnIntercomNotification(): void
{
$notification = new Notification();

$this->expectException(InvalidArgumentException::class);
$this->channel->send(new TestNotifiable(), $notification);
}

public function testItThrowsAnExceptionWhenRecipientIsNotProvided()
public function testItThrowsAnExceptionWhenRecipientIsNotProvided(): void
{
$notification = new TestNotification(
IntercomMessage::create('Hello World!')
Expand All @@ -89,7 +89,7 @@ public function testItThrowsAnExceptionWhenRecipientIsNotProvided()
$this->channel->send(new TestNotifiable(), $notification);
}

public function testItThrowsAnExceptionSomeOfRequiredParamsAreNotDefined()
public function testItThrowsAnExceptionSomeOfRequiredParamsAreNotDefined(): void
{
$notification = new TestNotification(
IntercomMessage::create()
Expand Down Expand Up @@ -129,6 +129,6 @@ public function testItGetsToFromRouteNotificationForIntercomMethod(): void
$expected = ['type' => 'user', 'id' => 321];
$this->channel->send(new TestNotifiable($expected), $notification);

$this->assertEquals($expected, $message->payload['to']);
self::assertEquals($expected, $message->payload['to']);
}
}
54 changes: 27 additions & 27 deletions tests/IntercomMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,90 @@

namespace FtwSoft\NotificationChannels\Intercom\Tests;

use PHPUnit\Framework\TestCase;
use FtwSoft\NotificationChannels\Intercom\IntercomMessage;
use PHPUnit\Framework\TestCase;

class IntercomMessageTest extends TestCase
{
public function testThatTypeInappConstantSetCorrectly(): void
{
$this->assertEquals('inapp', IntercomMessage::TYPE_INAPP);
self::assertEquals('inapp', IntercomMessage::TYPE_INAPP);
}

public function testThatTypeEmailConstantSetCorrectly(): void
{
$this->assertEquals('email', IntercomMessage::TYPE_EMAIL);
self::assertEquals('email', IntercomMessage::TYPE_EMAIL);
}

public function testThatTemplatePlainConstantSetCorrectly(): void
{
$this->assertEquals('plain', IntercomMessage::TEMPLATE_PLAIN);
self::assertEquals('plain', IntercomMessage::TEMPLATE_PLAIN);
}

public function testThatTemplatePersonalConstantSetCorrectly(): void
{
$this->assertEquals('personal', IntercomMessage::TEMPLATE_PERSONAL);
self::assertEquals('personal', IntercomMessage::TEMPLATE_PERSONAL);
}

public function testItAcceptsBodyWhenConstructed(): void
{
$message = new IntercomMessage('Intercom message test');
$this->assertEquals('Intercom message test', $message->payload['body']);
self::assertEquals('Intercom message test', $message->payload['body']);
}

public function testThatDefaultMessageTypeIsInapp(): void
{
$message = new IntercomMessage();
$this->assertEquals(IntercomMessage::TYPE_INAPP, $message->payload['message_type']);
self::assertEquals(IntercomMessage::TYPE_INAPP, $message->payload['message_type']);
}

public function testThatBodyCanBeSet(): void
{
$message = new IntercomMessage('Intercom message test');
$message->body('Some other intercom body');
$this->assertEquals('Some other intercom body', $message->payload['body']);
self::assertEquals('Some other intercom body', $message->payload['body']);
}

public function testThatMessageTypeToEmailCanBeSet(): void
{
$message = new IntercomMessage();
$message->email();
$this->assertEquals(IntercomMessage::TYPE_EMAIL, $message->payload['message_type']);
self::assertEquals(IntercomMessage::TYPE_EMAIL, $message->payload['message_type']);
}

public function testThatMessageTypeToInappCanBeSet(): void
{
$message = new IntercomMessage();
$message->email()->inapp();
$this->assertEquals(IntercomMessage::TYPE_INAPP, $message->payload['message_type']);
self::assertEquals(IntercomMessage::TYPE_INAPP, $message->payload['message_type']);
}

public function testThatSubjectCanBeSet(): void
{
$message = new IntercomMessage();
$message->subject('Some interesting subject');
$this->assertEquals('Some interesting subject', $message->payload['subject']);
self::assertEquals('Some interesting subject', $message->payload['subject']);
}

public function testThatTemplatePlainCanBeSet(): void
{
$message = new IntercomMessage();
$message->plain();
$this->assertEquals(IntercomMessage::TEMPLATE_PLAIN, $message->payload['template']);
self::assertEquals(IntercomMessage::TEMPLATE_PLAIN, $message->payload['template']);
}

public function testThatTemplatePersonalCanBeSet(): void
{
$message = new IntercomMessage();
$message->personal();
$this->assertEquals(IntercomMessage::TEMPLATE_PERSONAL, $message->payload['template']);
self::assertEquals(IntercomMessage::TEMPLATE_PERSONAL, $message->payload['template']);
}

public function testThatSenderCanBeSet(): void
{
$message = new IntercomMessage();
$message->from(123);
$this->assertEquals(
self::assertEquals(
[
'type' => 'admin',
'id' => 123,
Expand All @@ -103,14 +103,14 @@ public function testThatRecipientCanBeSet(): void
];
$message->to($expected);

$this->assertEquals($expected, $message->payload['to']);
self::assertEquals($expected, $message->payload['to']);
}

public function testThatRecipientUserIdCanBeSet(): void
{
$message = new IntercomMessage();
$message->toUserId(456);
$this->assertEquals(
self::assertEquals(
[
'type' => 'user',
'id' => 456,
Expand All @@ -123,7 +123,7 @@ public function testThatRecipientUserEmailCanBeSet(): void
{
$message = new IntercomMessage();
$message->toUserEmail('foo@bar.com');
$this->assertEquals(
self::assertEquals(
[
'type' => 'user',
'email' => 'foo@bar.com',
Expand All @@ -136,7 +136,7 @@ public function testThatContactIdCanBeSet(): void
{
$message = new IntercomMessage();
$message->toContactId(789);
$this->assertEquals(
self::assertEquals(
[
'type' => 'contact',
'id' => 789,
Expand All @@ -148,25 +148,25 @@ public function testThatContactIdCanBeSet(): void
public function testItCanDetermiteIfToIsNotGiven()
{
$message = new IntercomMessage();
$this->assertFalse($message->toIsGiven());
self::assertFalse($message->toIsGiven());

$message->toUserId(123);
$this->assertTrue($message->toIsGiven());
self::assertTrue($message->toIsGiven());
}

public function testInCanDetermineWhenRequiredParamsAreNotSet(): void
{
$message = new IntercomMessage();
$this->assertFalse($message->isValid());
self::assertFalse($message->isValid());

$message->body('Some body');
$this->assertFalse($message->isValid());
self::assertFalse($message->isValid());

$message->from(123);
$this->assertFalse($message->isValid());
self::assertFalse($message->isValid());

$message->toUserId(321);
$this->assertTrue($message->isValid());
self::assertTrue($message->isValid());
}

public function testItCanReturnPayloadAsAnArray(): void
Expand Down Expand Up @@ -196,15 +196,15 @@ public function testItCanReturnPayloadAsAnArray(): void
'body' => 'Some message',
];

$this->assertEquals($expected, $message->toArray());
self::assertEquals($expected, $message->toArray());
}

public function testThatStaticCreateMethodProvidesBodyToObject(): void
{
$message = IntercomMessage::create();
$this->assertFalse(isset($message->payload['body']));
self::assertFalse(isset($message->payload['body']));

$message = IntercomMessage::create('Intercom message test');
$this->assertEquals('Intercom message test', $message->payload['body']);
self::assertEquals('Intercom message test', $message->payload['body']);
}
}
14 changes: 7 additions & 7 deletions tests/IntercomServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace FtwSoft\NotificationChannels\Intercom\Tests;

use PHPUnit\Framework\TestCase;
use Illuminate\Support\Facades\Config;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Notification;
use FtwSoft\NotificationChannels\Intercom\IntercomChannel;
use FtwSoft\NotificationChannels\Intercom\IntercomServiceProvider;
use FtwSoft\NotificationChannels\Intercom\Tests\Mocks\TestFakeApplication;
use FtwSoft\NotificationChannels\Intercom\Tests\Mocks\TestConfigRepository;
use FtwSoft\NotificationChannels\Intercom\Tests\Mocks\TestFakeApplication;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Notification;
use PHPUnit\Framework\TestCase;

class IntercomServiceProviderTest extends TestCase
{
Expand Down Expand Up @@ -46,13 +46,13 @@ public function testItBootsAndProvidesDIForIntercomClientFromConfig(): void
/** @var IntercomChannel $client */
$client = $this->app->make(IntercomChannel::class);

$this->assertEquals('SOME_TOKEN', $client->getClient()->getAuth()[0]);
self::assertEquals('SOME_TOKEN', $client->getClient()->getAuth()[0]);
}

public function testItRegistersNewIntercomNorificationDriverAlias(): void
{
$this->serviceProvider->register();

$this->assertInstanceOf(IntercomChannel::class, Notification::driver('intercom'));
self::assertInstanceOf(IntercomChannel::class, Notification::driver('intercom'));
}
}
6 changes: 3 additions & 3 deletions tests/MessageIsNotCompleteExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace FtwSoft\NotificationChannels\Intercom\Tests;

use PHPUnit\Framework\TestCase;
use FtwSoft\NotificationChannels\Intercom\IntercomMessage;
use FtwSoft\NotificationChannels\Intercom\Exceptions\MessageIsNotCompleteException;
use FtwSoft\NotificationChannels\Intercom\IntercomMessage;
use PHPUnit\Framework\TestCase;

class MessageIsNotCompleteExceptionTest extends TestCase
{
public function testItReturnsMessageProvidedToConstruct(): void
{
$message = IntercomMessage::create('TEST');
$exception = new MessageIsNotCompleteException($message);
$this->assertEquals($message, $exception->getIntercomMessage());
self::assertEquals($message, $exception->getIntercomMessage());
}
}
Loading

0 comments on commit fdef9b2

Please sign in to comment.