Skip to content

Commit

Permalink
Merge pull request #266 from fenos/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Gummibeer authored Feb 6, 2017
2 parents bc589a0 + 207ddae commit 16e7d72
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 33 deletions.
23 changes: 15 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ addons:
code_climate:
repo_token: ${CC_TOKEN}

## Services used by this package
services:
- mysql

## List all PHP versions to test with
php:
- 5.5
- 5.6
- 7.0
- 7.1
Expand All @@ -29,24 +32,27 @@ env:
- LARAVEL_VERSION="5.2.*"
- LARAVEL_VERSION="5.3.*"
- LARAVEL_VERSION="5.4.*"
- LARAVEL_VERSION="dev-master"

matrix:
fast_finish: true
exclude:
- php: 5.5
env: LARAVEL_VERSION="5.3.*"
- php: 5.5
env: LARAVEL_VERSION="5.4.*"
include:
- php: 5.5
env: LARAVEL_VERSION="dev-master"
env: LARAVEL_VERSION="5.1.*"
- php: 5.6
env: LARAVEL_VERSION="5.1.*" DB_TYPE="mysql"
- php: 7.1
env: LARAVEL_VERSION="5.4.*" DB_TYPE="mysql"
- php: 7.1
env: LARAVEL_VERSION="dev-master"
allow_failures:
- php: nightly
- php: hhvm
- env: LARAVEL_VERSION="dev-master"

## Run Scripts before Install
before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS notifynder;'

## Install Dependencies
install:
- composer self-update
Expand All @@ -62,6 +68,7 @@ before_script:
script:
- vendor/bin/phpunit

## Run Scripts after Tests
after_script:
- vendor/bin/test-reporter
- export CI_BUILD_NUMBER="$TRAVIS_BUILD_NUMBER"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"codeclimate/php-test-reporter": "^0.3.2",
"satooshi/php-coveralls": "^1.0"
},
"suggests": {
"suggest": {
"astrotomic/notifynder-sender-email": "Allows to send notifications as email.",
"astrotomic/notifynder-sender-redis": "Allows to send notifications via Redis (Pub/Sub).",
"astrotomic/notifynder-sender-slack": "Allows to send notifications via Slack.",
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_DRIVER" value="sqlite"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class DropVersion4UnusedTables extends Migration
*/
public function up()
{
Schema::dropIfExists('notification_groups');
Schema::dropIfExists('notifications_categories_in_groups');
Schema::dropIfExists('notification_groups');
}

/**
Expand Down
39 changes: 34 additions & 5 deletions tests/NotifynderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Fenos\Tests\Models\CarL53;
use Fenos\Tests\Models\UserL53;
use Illuminate\Database\Eloquent\Model;
use Fenos\Notifynder\Models\Notification;
use Fenos\Notifynder\NotifynderServiceProvider;
use Fenos\Notifynder\Models\NotificationCategory;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
Expand All @@ -29,7 +30,6 @@ protected function getPackageAliases($app)
public function setUp()
{
parent::setUp();
// This should only do work for Sqlite DBs in memory.
$artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
app('db')->beginTransaction();
$this->migrate($artisan);
Expand All @@ -41,17 +41,40 @@ public function setUp()

protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
$app['config']->set('database.connections.test_sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app['config']->set('database.connections.test_mysql', [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'database' => 'notifynder',
'username' => 'travis',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
]);
if (env('DB_TYPE', 'sqlite') == 'mysql') {
$app['config']->set('database.default', 'test_mysql');
} else {
$app['config']->set('database.default', 'test_sqlite');
}
}

public function tearDown()
{
app('db')->rollback();
if (app('db')->getDriverName() == 'mysql') {
app('db')->statement('SET FOREIGN_KEY_CHECKS=0;');
Notification::truncate();
NotificationCategory::truncate();
app('db')->statement('SET FOREIGN_KEY_CHECKS=1;');
}
}

protected function getApplicationTimezone($app)
Expand All @@ -62,7 +85,6 @@ protected function getApplicationTimezone($app)
protected function migrate($artisan, $path = '/../../../../src/migrations')
{
$artisan->call('migrate', [
'--database' => 'testbench',
'--path' => $path,
]);
}
Expand All @@ -74,6 +96,11 @@ protected function createCategory(array $attributes = [])
'name' => 'test.category',
], $attributes);

$category = NotificationCategory::byName($attributes['name'])->first();
if ($category instanceof NotificationCategory) {
return $category;
}

return NotificationCategory::create($attributes);
}

Expand Down Expand Up @@ -107,8 +134,10 @@ protected function createCar(array $attributes = [])

protected function sendNotificationTo(Model $model)
{
$category = $this->createCategory();

return $model
->sendNotificationTo(1)
->sendNotificationTo($category->getKey())
->from(2)
->send();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/Facades/NotifynderFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class NotifynderFacadeTest extends NotifynderTestCase
{
public function testSendSingleNotification()
{
$sent = \Notifynder::category(1)
$category = $this->createCategory();
$sent = \Notifynder::category($category->getKey())
->from(1)
->to(2)
->send();
Expand Down
24 changes: 15 additions & 9 deletions tests/integration/Managers/NotifynderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function testBuildMultipleNotifications()
public function testSendSingleNotification()
{
$manager = app('notifynder');
$sent = $manager->category(1)
$category = $this->createCategory();
$sent = $manager->category($category->getKey())
->from(1)
->to(2)
->send();
Expand All @@ -76,7 +77,8 @@ public function testSendSingleNotification()
public function testSendSingleAnonymousNotification()
{
$manager = app('notifynder');
$sent = $manager->category(1)
$category = $this->createCategory();
$sent = $manager->category($category->getKey())
->anonymous()
->to(2)
->send();
Expand All @@ -98,8 +100,9 @@ public function testSendMultipleNotifications()
{
$datas = [2, 3, 4];
$manager = app('notifynder');
$sent = $manager->loop($datas, function ($builder, $data) {
$builder->category(1)
$category = $this->createCategory();
$sent = $manager->loop($datas, function ($builder, $data) use ($category) {
$builder->category($category->getKey())
->from(1)
->to($data);
})->send();
Expand All @@ -114,7 +117,8 @@ public function testSendMultipleNotifications()
public function testSendSingleSpecificNotification()
{
$manager = app('notifynder');
$sent = $manager->category(1)
$category = $this->createCategory();
$sent = $manager->category($category->getKey())
->from(1)
->to(2)
->sendSingle();
Expand All @@ -129,7 +133,8 @@ public function testSendSingleSpecificNotification()
public function testSendOnceSameNotifications()
{
$manager = app('notifynder');
$sent = $manager->category(1)
$category = $this->createCategory();
$sent = $manager->category($category->getKey())
->from(1)
->to(2)
->extra(['foo' => 'bar'])
Expand All @@ -148,7 +153,7 @@ public function testSendOnceSameNotifications()

sleep(1);

$sent = $manager->category(1)
$sent = $manager->category($category->getKey())
->from(1)
->to(2)
->extra(['foo' => 'bar'])
Expand All @@ -172,7 +177,8 @@ public function testSendOnceSameNotifications()
public function testSendOnceDifferentNotifications()
{
$manager = app('notifynder');
$sent = $manager->category(1)
$category = $this->createCategory();
$sent = $manager->category($category->getKey())
->from(1)
->to(2)
->extra(['foo' => 'bar'])
Expand All @@ -183,7 +189,7 @@ public function testSendOnceDifferentNotifications()
$this->assertCount(1, $notifications);
$this->assertInstanceOf(EloquentCollection::class, $notifications);

$sent = $manager->category(1)
$sent = $manager->category($category->getKey())
->from(2)
->to(1)
->extra(['hello' => 'world'])
Expand Down
17 changes: 10 additions & 7 deletions tests/integration/Traits/NotifableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,42 @@ public function testNotifynder()

public function testSendNotificationFrom()
{
$category = $this->createCategory();
$user = $this->createUser();
$notifynder = $user->sendNotificationFrom(1);
$notifynder = $user->sendNotificationFrom($category->getKey());
$this->assertInstanceOf(NotifynderManager::class, $notifynder);
$notifynder->to(2);
$builder = $notifynder->builder();
$this->assertInstanceOf(Builder::class, $builder);
$notification = $builder->getNotification();
$this->assertInstanceOf(Notification::class, $notification);
$this->assertSame(1, $notification->category_id);
$this->assertSame(1, $notification->from_id);
$this->assertSame($category->getKey(), $notification->category_id);
$this->assertSame($user->getKey(), $notification->from_id);
}

public function testSendNotificationTo()
{
$category = $this->createCategory();
$user = $this->createUser();
$notifynder = $user->sendNotificationTo(1);
$notifynder = $user->sendNotificationTo($category->getKey());
$this->assertInstanceOf(NotifynderManager::class, $notifynder);
$notifynder->from(2);
$builder = $notifynder->builder();
$this->assertInstanceOf(Builder::class, $builder);
$notification = $builder->getNotification();
$this->assertInstanceOf(Notification::class, $notification);
$this->assertSame(1, $notification->category_id);
$this->assertSame(1, $notification->to_id);
$this->assertSame($category->getKey(), $notification->category_id);
$this->assertSame($user->getKey(), $notification->to_id);
$notifynder->send();
$this->assertCount(1, $user->getNotificationRelation);
}

public function testNotificationsHasMany()
{
$category = $this->createCategory();
$user = $this->createUser();
$user
->sendNotificationTo(1)
->sendNotificationTo($category->getKey())
->from(2)
->send();
$this->assertCount(1, $user->getNotificationRelation);
Expand Down

0 comments on commit 16e7d72

Please sign in to comment.