Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Restored some tests.
James Cole240f3c126bb9
diff --git a/.env.testing b/.env.testingnew file mode 100755index 0000000000..3c9802e829--- /dev/null+++ b/.env.testing@@ -0,0 +1,45 @@+APP_ENV=testing+APP_DEBUG=true+APP_FORCE_SSL=false+APP_FORCE_ROOT=+APP_KEY=TestTestTestTestTestTestTestTest+APP_LOG_LEVEL=debug+APP_URL=http://localhost++DB_CONNECTION=sqlite+DB_HOST=127.0.0.1+DB_PORT=3306+DB_USERNAME=homestead+DB_PASSWORD=secret++BROADCAST_DRIVER=log+CACHE_DRIVER=file+SESSION_DRIVER=file+QUEUE_DRIVER=sync++COOKIE_PATH="/"+COOKIE_DOMAIN=+COOKIE_SECURE=false++REDIS_HOST=127.0.0.1+REDIS_PASSWORD=null+REDIS_PORT=6379++MAIL_DRIVER=smtp+MAIL_HOST=mailtrap.io+MAIL_PORT=2525+MAIL_USERNAME=null+MAIL_PASSWORD=null+MAIL_ENCRYPTION=null++SEND_REGISTRATION_MAIL=true+SEND_ERROR_MESSAGE=true+SHOW_INCOMPLETE_TRANSLATIONS=false++ANALYTICS_ID=++PUSHER_KEY=+PUSHER_SECRET=+PUSHER_APP_ID=diff --git a/config/database.php b/config/database.phpindex 81a863d474..451ffd9741 100755--- a/config/database.php+++ b/config/database.php@@ -11,120 +11,51 @@return [- /*- |--------------------------------------------------------------------------- | PDO Fetch Style- |--------------------------------------------------------------------------- |- | By default, database results will be returned as instances of the PHP- | stdClass object; however, you may desire to retrieve records in an- | array format for simplicity. Here you can tweak the fetch style.- |- */-- 'fetch' => PDO::FETCH_OBJ,-- /*- |--------------------------------------------------------------------------- | Default Database Connection Name- |--------------------------------------------------------------------------- |- | Here you may specify which of the database connections below you wish- | to use as your default connection for all database work. Of course- | you may use many connections at once using the Database library.- |- */-- 'default' => env('DB_CONNECTION', 'mysql'),-- /*- |--------------------------------------------------------------------------- | Database Connections- |--------------------------------------------------------------------------- |- | Here are each of the database connections setup for your application.- | Of course, examples of configuring each database platform that is- | supported by Laravel is shown below to make development simple.- |- |- | All database work in Laravel is done through the PHP PDO facilities- | so make sure you have the driver for your particular database of- | choice installed on your machine before you begin development.- |- */-+ 'fetch' => PDO::FETCH_OBJ,+ 'default' => env('DB_CONNECTION', 'mysql'),'connections' => [-'sqlite' => [- 'driver' => 'sqlite',- 'database' => env('DB_DATABASE', database_path('database.sqlite')),- 'prefix' => '',+ 'driver' => 'sqlite',+ 'database' => env('DB_DATABASE', storage_path('database/database.sqlite')),+ 'prefix' => '',],'mysql' => [- 'driver' => 'mysql',- 'host' => env('DB_HOST', 'localhost'),- 'port' => env('DB_PORT', '3306'),- 'database' => env('DB_DATABASE', 'forge'),- 'username' => env('DB_USERNAME', 'forge'),- 'password' => env('DB_PASSWORD', ''),- 'charset' => 'utf8',+ 'driver' => 'mysql',+ 'host' => env('DB_HOST', 'localhost'),+ 'port' => env('DB_PORT', '3306'),+ 'database' => env('DB_DATABASE', 'forge'),+ 'username' => env('DB_USERNAME', 'forge'),+ 'password' => env('DB_PASSWORD', ''),+ 'charset' => 'utf8','collation' => 'utf8_unicode_ci',- 'prefix' => '',- 'strict' => true,- 'engine' => null,+ 'prefix' => '',+ 'strict' => true,+ 'engine' => null,],'pgsql' => [- 'driver' => 'pgsql',- 'host' => env('DB_HOST', 'localhost'),- 'port' => env('DB_PORT', '5432'),+ 'driver' => 'pgsql',+ 'host' => env('DB_HOST', 'localhost'),+ 'port' => env('DB_PORT', '5432'),'database' => env('DB_DATABASE', 'forge'),'username' => env('DB_USERNAME', 'forge'),'password' => env('DB_PASSWORD', ''),- 'charset' => 'utf8',- 'prefix' => '',- 'schema' => 'public',- 'sslmode' => 'prefer',+ 'charset' => 'utf8',+ 'prefix' => '',+ 'schema' => 'public',+ 'sslmode' => 'prefer',],],-- /*- |--------------------------------------------------------------------------- | Migration Repository Table- |--------------------------------------------------------------------------- |- | This table keeps track of all the migrations that have already run for- | your application. Using this information, we can determine which of- | the migrations on disk haven't actually been run in the database.- |- */-- 'migrations' => 'migrations',-- /*- |--------------------------------------------------------------------------- | Redis Databases- |--------------------------------------------------------------------------- |- | Redis is an open source, fast, and advanced key-value store that also- | provides a richer set of commands than a typical key-value systems- | such as APC or Memcached. Laravel makes it easy to dig right in.- |- */-- 'redis' => [-+ 'migrations' => 'migrations',+ 'redis' => ['cluster' => false,-'default' => [- 'host' => env('REDIS_HOST', 'localhost'),+ 'host' => env('REDIS_HOST', 'localhost'),'password' => env('REDIS_PASSWORD', null),- 'port' => env('REDIS_PORT', 6379),+ 'port' => env('REDIS_PORT', 6379),'database' => 0,],-],-];diff --git a/database/migrations/2016_08_25_091522_changes_for_3101.php b/database/migrations/2016_08_25_091522_changes_for_3101.phpindex 24883b7933..15a0c54afd 100644--- a/database/migrations/2016_08_25_091522_changes_for_3101.php+++ b/database/migrations/2016_08_25_091522_changes_for_3101.php@@ -37,7 +37,7 @@ class ChangesFor3101 extends Migration{Schema::table('import_jobs', function (Blueprint $table) {- $table->text('extended_status');+ $table->text('extended_status')->nullable();});}diff --git a/test.sh b/test.shnew file mode 100755index 0000000000..6c2e7847fd--- /dev/null+++ b/test.sh@@ -0,0 +1,41 @@+#!/bin/bash++DATABASE=storage/database/database.sqlite+DATABASECOPY=storage/database/databasecopy.sqlite+++# backup current config:+mv .env .env.current++# enable testing config+cp .env.testing .env++# clear cache:+php artisan cache:clear++if [ "$1" == "--reset" ]; then+ echo "Must reset database"++ # touch files to make sure they exist.+ touch $DATABASE+ touch $DATABASECOPY++ # truncate original database file+ truncate $DATABASE --size 0++ # run migration+ php artisan migrate:refresh --seed++ # copy new database over backup (resets backup)+ cp $DATABASE $DATABASECOPY+fi++# take database from copy:+cp $DATABASECOPY $DATABASE++# run PHPUnit++phpunit++# restore current config:+mv .env.current .env\ No newline at end of filediff --git a/tests/ExampleTest.php b/tests/ExampleTest.phpindex 451bd48bed..5f8b620794 100755--- a/tests/ExampleTest.php+++ b/tests/ExampleTest.php@@ -1,9 +1,5 @@<?php-use Illuminate\Foundation\Testing\WithoutMiddleware;-use Illuminate\Foundation\Testing\DatabaseMigrations;-use Illuminate\Foundation\Testing\DatabaseTransactions;-/*** Class ExampleTest*/@@ -17,6 +13,6 @@ class ExampleTest extends TestCasepublic function testBasicExample(){$this->visit('/')- ->see('Laravel');+ ->see('Firefly');}}diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 2781681df5..79e8cbf40b 100755--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -1,5 +1,9 @@<?php+use Carbon\Carbon;+use FireflyIII\Models\Preference;+use FireflyIII\User;+/*** Class TestCase*/@@ -12,6 +16,35 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase*/protected $baseUrl = 'http://localhost';+ /**+ * @param User $user+ * @param string $range+ */+ public function changeDateRange(User $user, $range)+ {+ $valid = ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'];+ if (in_array($range, $valid)) {+ Preference::where('user_id', $user->id)->where('name', 'viewRange')->delete();+ Preference::create(+ [+ 'user_id' => $user->id,+ 'name' => 'viewRange',+ 'data' => $range,+ ]+ );+ // set period to match?++ }+ if ($range === 'custom') {+ $this->session(+ [+ 'start' => Carbon::now()->subDays(20),+ 'end' => Carbon::now(),+ ]+ );+ }+ }+/*** Creates the application.*@@ -19,10 +52,62 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase*/public function createApplication(){- $app = require __DIR__.'/../bootstrap/app.php';+ $app = require __DIR__ . '/../bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();return $app;}++ /**+ * @return array+ */+ public function dateRangeProvider()+ {+ return [+ 'one day' => ['1D'],+ 'one week' => ['1W'],+ 'one month' => ['1M'],+ 'three months' => ['3M'],+ 'six months' => ['6M'],+ 'one year' => ['1Y'],+ 'custom range' => ['custom'],+ ];+ }++ /**+ * Sets up the fixture, for example, opens a network connection.+ * This method is called before a test is executed.+ */+ public function setUp()+ {+ parent::setUp();++ }+++ /**+ * @return User+ */+ public function user()+ {+ $user = User::find(1);++ return $user;+ }++ /**+ * @param string $class+ *+ * @return \Mockery\MockInterface+ */+ protected function mock($class)+ {+ $object = Mockery::mock($class);+++ $this->app->instance($class, $object);++ return $object;+ }}diff --git a/tests/acceptance/Controllers/HomeControllerTest.php b/tests/acceptance/Controllers/HomeControllerTest.phpnew file mode 100755index 0000000000..7d4abdcdc8--- /dev/null+++ b/tests/acceptance/Controllers/HomeControllerTest.php@@ -0,0 +1,63 @@+<?php++/**+ * HomeControllerTest.php+ * Copyright (C) 2016 [email protected]+ *+ * This software may be modified and distributed under the terms of the+ * Creative Commons Attribution-ShareAlike 4.0 International License.+ *+ * See the LICENSE file for details.+ */+class HomeControllerTest extends TestCase+{+ public function displayError()+ {+ $this->assertTrue(true);+ }++ /**+ * @covers FireflyIII\Http\Controllers\HomeController::dateRange+ * @covers FireflyIII\Http\Controllers\HomeController::__construct+ */+ public function testDateRange()+ {++ $this->be($this->user());++ $args = [+ 'start' => '2012-01-01',+ 'end' => '2012-04-01',+ ];++ // if date range is > 50, should have flash.+ $this->call('POST', '/daterange', $args);+ $this->assertResponseStatus(200);+ $this->assertSessionHas('warning', '91 days of data may take a while to load.');+ }++ /**+ * @covers FireflyIII\Http\Controllers\HomeController::flush+ */+ public function testFlush()+ {+ $this->be($this->user());+ $this->call('GET', '/flush');+ $this->assertResponseStatus(302);+ }++ /**+ * @covers FireflyIII\Http\Controllers\HomeController::index+ * @covers FireflyIII\Http\Controllers\Controller::__construct+ * @dataProvider dateRangeProvider+ *+ * @param $range+ */+ public function testIndex($range)+ {+ $this->be($this->user());+ $this->changeDateRange($this->user(), $range);+ $this->call('GET', '/');+ $this->assertResponseStatus(200);+ }+}diff --git a/tests/unit/Models/TransactionTypeTest.php b/tests/unit/Models/TransactionTypeTest.phpnew file mode 100755index 0000000000..e0c3f2aa86--- /dev/null+++ b/tests/unit/Models/TransactionTypeTest.php@@ -0,0 +1,43 @@+<?php+/**+ * TransactionTypeTest.php+ * Copyright (C) 2016 [email protected]+ *+ * This software may be modified and distributed under the terms of the+ * Creative Commons Attribution-ShareAlike 4.0 International License.+ *+ * See the LICENSE file for details.+ */++use FireflyIII\Models\TransactionType;+++/**+ * Class TransactionTypeTest+ */+class TransactionTypeTest extends TestCase+{+ public function testIsDeposit()+ {+ $transactionType = TransactionType::whereType(TransactionType::DEPOSIT)->first();+ $this->assertTrue($transactionType->isDeposit());+ }++ public function testIsOpeningBalance()+ {+ $transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();+ $this->assertTrue($transactionType->isOpeningBalance());+ }++ public function testIsTransfer()+ {+ $transactionType = TransactionType::whereType(TransactionType::TRANSFER)->first();+ $this->assertTrue($transactionType->isTransfer());+ }++ public function testIsWithdrawal()+ {+ $transactionType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();+ $this->assertTrue($transactionType->isWithdrawal());+ }+}