diff --git a/.travis.yml b/.travis.yml index 3d013f7..20e2db3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 @@ -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" diff --git a/composer.json b/composer.json index da44b2d..53feab7 100644 --- a/composer.json +++ b/composer.json @@ -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.", diff --git a/phpunit.xml b/phpunit.xml index ebefb65..c203337 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -31,7 +31,6 @@ - diff --git a/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php b/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php index b0af3a7..ad8c72f 100644 --- a/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php +++ b/src/migrations/2016_11_02_193415_drop_version4_unused_tables.php @@ -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'); } /** diff --git a/tests/NotifynderTestCase.php b/tests/NotifynderTestCase.php index 9d3df9b..4d9a200 100644 --- a/tests/NotifynderTestCase.php +++ b/tests/NotifynderTestCase.php @@ -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; @@ -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); @@ -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) @@ -62,7 +85,6 @@ protected function getApplicationTimezone($app) protected function migrate($artisan, $path = '/../../../../src/migrations') { $artisan->call('migrate', [ - '--database' => 'testbench', '--path' => $path, ]); } @@ -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); } @@ -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(); } diff --git a/tests/integration/Facades/NotifynderFacadeTest.php b/tests/integration/Facades/NotifynderFacadeTest.php index dc53262..8a5fbfe 100644 --- a/tests/integration/Facades/NotifynderFacadeTest.php +++ b/tests/integration/Facades/NotifynderFacadeTest.php @@ -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(); diff --git a/tests/integration/Managers/NotifynderManagerTest.php b/tests/integration/Managers/NotifynderManagerTest.php index c6c3010..29c9888 100644 --- a/tests/integration/Managers/NotifynderManagerTest.php +++ b/tests/integration/Managers/NotifynderManagerTest.php @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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']) @@ -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']) @@ -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']) @@ -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']) diff --git a/tests/integration/Traits/NotifableTest.php b/tests/integration/Traits/NotifableTest.php index c17bbdf..99e81f1 100644 --- a/tests/integration/Traits/NotifableTest.php +++ b/tests/integration/Traits/NotifableTest.php @@ -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);