Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3abe408
first try to use mysql for tests
Gummibeer Feb 6, 2017
45bd15e
Apply fixes from StyleCI
Gummibeer Feb 6, 2017
ff049da
Merge pull request #259 from fenos/analysis-XZxjYb
fenos Feb 6, 2017
ff67195
remove comment
Gummibeer Feb 6, 2017
8f09794
change order to remove tables
Gummibeer Feb 6, 2017
91c5335
Merge remote-tracking branch 'origin/develop' into develop
Gummibeer Feb 6, 2017
157cbf1
fix mysql test errors (category id constraints)
Gummibeer Feb 6, 2017
9f177c7
Apply fixes from StyleCI
Gummibeer Feb 6, 2017
10a6d2f
Merge pull request #260 from fenos/analysis-XNm63e
fenos Feb 6, 2017
9ae3018
fix mysql test errors (category name constraints)
Gummibeer Feb 6, 2017
4cd41e0
Merge remote-tracking branch 'origin/develop' into develop
Gummibeer Feb 6, 2017
1bfe16b
Apply fixes from StyleCI
Gummibeer Feb 6, 2017
951574f
Merge pull request #261 from fenos/analysis-XkBa0a
fenos Feb 6, 2017
886a75e
try to optimize build matrix
Gummibeer Feb 6, 2017
2227b39
fix last mysql constrains related test errors
Gummibeer Feb 6, 2017
32c54b9
Merge remote-tracking branch 'origin/develop' into develop
Gummibeer Feb 6, 2017
e4a059f
Apply fixes from StyleCI
Gummibeer Feb 6, 2017
f907f1d
Merge pull request #262 from fenos/analysis-XNmA6v
fenos Feb 6, 2017
f3783e4
fix truncate order
Gummibeer Feb 6, 2017
8869430
fix exclude envs
Gummibeer Feb 6, 2017
9b92cb8
#263 remove php5.5 from fulltest list
Gummibeer Feb 6, 2017
7ec7f8f
ignore constraints to truncate models on tearDown
Gummibeer Feb 6, 2017
5863c17
fix last assert id errors
Gummibeer Feb 6, 2017
6b42b4d
execute SET just on mysql
Gummibeer Feb 6, 2017
0a70664
Apply fixes from StyleCI
Gummibeer Feb 6, 2017
08c3650
Merge pull request #264 from fenos/analysis-XkBaYy
fenos Feb 6, 2017
7a0de6d
execute truncate just on mysql
Gummibeer Feb 6, 2017
dc6b212
Merge remote-tracking branch 'origin/develop' into develop
Gummibeer Feb 6, 2017
76218e2
Apply fixes from StyleCI
Gummibeer Feb 6, 2017
6960060
Merge pull request #265 from fenos/analysis-qB9Mor
fenos Feb 6, 2017
775fad5
fix enc exclude
Gummibeer Feb 6, 2017
f4eda27
Merge remote-tracking branch 'origin/develop' into develop
Gummibeer Feb 6, 2017
72d619f
fix suggest
Gummibeer Feb 6, 2017
3223a55
optimize build matrix
Gummibeer Feb 6, 2017
207ddae
optimize build matrix
Gummibeer Feb 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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