Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [Requirements](#requirements)
* [Installation](#installation)
* [Customizing Mercurius](#customizing-mercurius)
* [Testing](#testing)
* [Roadmap](#roadmap)
* [Support](#support)
* [Contributing](#contributing)
Expand Down Expand Up @@ -192,6 +193,25 @@ Please see [Customizing-Mercurius](CUSTOMIZING-MERCURIUS.md) for more informatio
<br>


## Testing
There are 2 different testsuites

### Application Testsuite
Run the following command to test the general application testsuite.
```
vendor/bin/phpunit
```

### Dusk Testsuite
Run the following command to test the Dusk testsuite.
```
vendor/bin/phpunit --testsuite=dusk
```


<br>


## Roadmap
Check the [roadmap](https://github.com/launcher-host/mercurius/issues/8) for more information.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"phpunit/phpunit": "^7.0",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^3.7",
"codeclimate/php-test-reporter": "dev-master"
"codeclimate/php-test-reporter": "dev-master",
"orchestra/testbench-dusk": "~3.7"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 9 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
stopOnError="false"
stopOnFailure="false"
verbose="true"
defaultTestSuite="app"
>
<testsuites>
<testsuite name="Mercurium Test Suite">
<directory>tests</directory>
<testsuite name="app">
<directory>tests/Unit</directory>
<directory>tests/Feature</directory>
</testsuite>
<testsuite name="dusk">
<directory>tests/Browser</directory>
</testsuite>
</testsuites>
<filter>
Expand All @@ -29,5 +34,7 @@
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
25 changes: 13 additions & 12 deletions src/MercuriusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Launcher\Mercurius;

use Carbon\Carbon;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Schema;
Expand Down Expand Up @@ -55,16 +56,16 @@ public function register()
*/
protected function registerPublishable()
{
$_path = __DIR__.'/../publishable/';
$path = __DIR__.'/../publishable/';

$publishable = [
'mercurius-config' => ["{$_path}config/mercurius.php" => config_path('mercurius.php')],
'mercurius-public' => ["{$_path}public" => public_path('vendor/mercurius')],
'mercurius-config' => ["{$path}config/mercurius.php" => config_path('mercurius.php')],
'mercurius-public' => ["{$path}public" => public_path('vendor/mercurius')],
'mercurius-sass' => [__DIR__.'/../resources/sass/' => resource_path('sass/vendor/mercurius')],
'mercurius-js' => [__DIR__.'/../resources/js/' => resource_path('js/vendor/mercurius')],
'mercurius-seeds' => ["{$_path}database/seeds/" => database_path('seeds')],
'mercurius-lang' => ["{$_path}lang/" => resource_path('lang')],
'mercurius-views' => ["{$_path}views/" => resource_path('views/vendor/mercurius')],
'mercurius-seeds' => ["{$path}database/seeds/" => database_path('seeds')],
'mercurius-lang' => ["{$path}lang/" => resource_path('lang')],
'mercurius-views' => ["{$path}views/" => resource_path('views/vendor/mercurius')],
];

foreach ($publishable as $group => $paths) {
Expand All @@ -79,17 +80,17 @@ protected function registerPublishable()
*/
private function registerPublishableMigrations()
{
if (!Schema::hasTable('mercurius_messages')) {
$_date = date('Y_m_d_His', time());
$_path = __DIR__.'/../publishable/database/migrations/';
//if (!Schema::hasTable('mercurius_messages')) {
$date = Carbon::now()->format('Y_m_d_His');
$path = __DIR__ . '/../publishable/database/migrations/';

$_migrations = [
"${_path}add_mercurius_user_fields.php" => database_path("migrations/${_date}_add_mercurius_user_fields.php"),
"${_path}create_mercurius_messages_table.php" => database_path("migrations/${_date}_create_mercurius_messages_table.php"),
"${path}add_mercurius_user_fields.php" => database_path("migrations/${date}_add_mercurius_user_fields.php"),
"${path}create_mercurius_messages_table.php" => database_path("migrations/${date}_create_mercurius_messages_table.php"),
];

$this->publishes($_migrations, 'mercurius-migrations');
}
//}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Repositories/ConversationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public function all($user = null)
' FROM',
' (',
' SELECT receiver_id as usr, MAX(id) AS id FROM '.$tbl_messages,
' WHERE deleted_by_sender IS FALSE AND sender_id ='.$user.' GROUP BY usr',
' WHERE deleted_by_sender IS 0 AND sender_id ='.$user.' GROUP BY usr',
' UNION ALL',
' SELECT sender_id as usr, MAX(id) as id FROM '.$tbl_messages,
' WHERE deleted_by_receiver IS FALSE AND receiver_id ='.$user.' GROUP BY usr',
' WHERE deleted_by_receiver IS 0 AND receiver_id ='.$user.' GROUP BY usr',
' ) u',
' GROUP BY u.usr',
' ) mm',
Expand Down Expand Up @@ -127,10 +127,10 @@ public function recipients($user = null)
'FROM',
' (',
' SELECT receiver_id as id FROM '.$tbl_messages,
' WHERE sender_id ='.$user.' AND deleted_by_receiver IS FALSE',
' WHERE sender_id ='.$user.' AND deleted_by_receiver IS 0',
' UNION ALL',
' SELECT sender_id as id FROM '.$tbl_messages,
' WHERE receiver_id ='.$user.' AND deleted_by_sender IS FALSE',
' WHERE receiver_id ='.$user.' AND deleted_by_sender IS 0',
') u',
]));

Expand Down
23 changes: 23 additions & 0 deletions tests/Browser/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Launcher\Mercurius\Tests\Browser;

use Launcher\Mercurius\Tests\DuskTestCase;

class ExampleTest extends DuskTestCase
{
protected $migrate = true;

public function test_browsing_frontpage()
{
$user = $this->userFactory()->create();

/*
$this->browse(function ($browser) use ($user) {
$response = $browser->loginAs($user)
->visit(route('mercurius.home'));
sleep(10);
});
*/
}
}
56 changes: 56 additions & 0 deletions tests/DuskTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Launcher\Mercurius\Tests;

use Carbon\Carbon;
use Illuminate\Foundation\Auth\User;
use Illuminate\Support\Facades\Artisan;
use Launcher\Mercurius\MercuriusServiceProvider;
use Orchestra\Testbench\Dusk\TestCase as TestCase;

class DuskTestCase extends TestCase
{
use HandlesExceptions;

protected $migrate = false;

public function setUp()
{
Carbon::setTestNow(Carbon::parse('2099-01-01 00:00:00'));

parent::setUp();

if ($this->migrate) {
$this->migrate();
}

$this->withFactories(__DIR__.'/Factories');

$this->disableExceptionHandling();
}

protected function getPackageProviders($app)
{
return [
MercuriusServiceProvider::class,
];
}

protected function userFactory()
{
return factory(User::class);
}

protected function migrate()
{
$this->loadLaravelMigrations();

Artisan::call('vendor:publish', [
'--tag' => 'mercurius-migrations',
]);

Carbon::setTestNow();

$this->artisan('migrate');
}
}
17 changes: 17 additions & 0 deletions tests/Factories/MessageFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Carbon\Carbon;
use Faker\Generator as Faker;
use Illuminate\Foundation\Auth\User;
use Launcher\Mercurius\Models\Message;

$factory->define(Message::class, function (Faker $faker) {
return [
'message' => $faker->sentence,
'sender_id' => factory(User::class),
'receiver_id' => factory(User::class),
'seen_at' => Carbon::now(),
'deleted_by_sender' => false,
'deleted_by_receiver' => false,
];
});
13 changes: 13 additions & 0 deletions tests/Factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Faker\Generator as Faker;
use Illuminate\Foundation\Auth\User;

$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
];
});
57 changes: 57 additions & 0 deletions tests/Feature/ConversationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Launcher\Mercurius\Tests\Feature;

use Carbon\Carbon;
use Illuminate\Foundation\Auth\User;
use Launcher\Mercurius\Tests\TestCase;

class ConversationTest extends TestCase
{
protected $migrate = true;

public function test_getting_conversations()
{
$user = $this->userFactory()->create();

$messageA = $this->messageFactory()->create([
'sender_id' => $user->id,
]);

$messageB = $this->messageFactory()->create([
'receiver_id' => $user->id,
]);

$users = User::all();

$response = $this->actingAs($user)
->get('/conversations')
->assertOk()
->assertJson([
[
'id' => '2',
'user' => $users->find(2)->name,
'avatar' => $users->find(2)->avatar,
'is_online' => '1',
'sender' => '1',
'message' => $messageA->message,
'seen_at' => Carbon::now()->toDateTimeString(),
'created_at' => Carbon::now()->toDateTimeString(),
],
[
'id' => '3',
'user' => $users->find(3)->name,
'avatar' => $users->find(2)->avatar,
'is_online' => '1',
'sender' => '3',
'message' => $messageB->message,
'seen_at' => Carbon::now()->toDateTimeString(),
'created_at' => Carbon::now()->toDateTimeString(),
]
]);
}

public function test_getting_recipients() {}
public function test_getting_converstion_with_given_user() {}
public function test_deleting_conversation() {}
}
11 changes: 11 additions & 0 deletions tests/Feature/MessageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Launcher\Mercurius\Tests\Feature;

use Launcher\Mercurius\Tests\TestCase;

class MessageTest extends TestCase
{
public function test_posting_message() {}
public function test_deleting_message() {}
}
25 changes: 25 additions & 0 deletions tests/Feature/ProfileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Launcher\Mercurius\Tests\Feature;

use Launcher\Mercurius\Tests\TestCase;

class ProfileTest extends TestCase
{
protected $migrate = true;

public function test_refreshing_profile()
{
$user = $this->userFactory()->create();

$response = $this->actingAs($user)
->get('/profile/refresh')
->assertOk()
->assertJson(array_except($user->toArray(), [
'email', 'password', 'remember_token', 'updated_at', 'created_at'
]));
}

public function test_getting_notifications() {}
public function test_updating_profile() {}
}
10 changes: 10 additions & 0 deletions tests/Feature/ReceiverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Launcher\Mercurius\Tests\Feature;

use Launcher\Mercurius\Tests\TestCase;

class ReceiverTest extends TestCase
{
public function test_searching_receiver() {}
}
Loading