From 1d73ff7c138475ab9bacb434b0f932bfe61111ad Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 2 Feb 2019 09:53:19 +0100 Subject: [PATCH] Fix test coverage. [skip ci] --- app/Support/Binder/Date.php | 5 +- changelog.md | 1 - tests/Unit/Factory/AccountFactoryTest.php | 2 +- tests/Unit/Middleware/BinderTest.php | 56 +++++++++++++---------- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php index 07462f9998..55aed73c56 100644 --- a/app/Support/Binder/Date.php +++ b/app/Support/Binder/Date.php @@ -63,7 +63,10 @@ class Date implements BinderInterface 'previousFiscalYearEnd' => $fiscalHelper->endOfFiscalYear(Carbon::now())->subYear(), ]; if (isset($magicWords[$value])) { - return $magicWords[$value]; + $return = $magicWords[$value]; + Log::debug(sprintf('User requests "%s", so will return "%s"', $value, $return)); + + return $return; } try { diff --git a/changelog.md b/changelog.md index dbc1f2eec1..4c725471dd 100644 --- a/changelog.md +++ b/changelog.md @@ -64,7 +64,6 @@ This project adheres to [Semantic Versioning](http://semver.org/). - New tag cloud in API. - See the [API docs](https://api-docs.firefly-iii.org/) for more information. ## [4.7.9] - 2018-12-25 diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.php index 35d7c07c59..490fa1ed42 100644 --- a/tests/Unit/Factory/AccountFactoryTest.php +++ b/tests/Unit/Factory/AccountFactoryTest.php @@ -559,7 +559,7 @@ class AccountFactoryTest extends TestCase /** @var AccountMeta $meta */ $currencyId = $account->accountMeta()->where('name', 'currency_id')->first(); $this->assertNotNull($currencyId); - $this->assertEquals($currency->id, $currencyId->data); + $this->assertEquals((int)$currency->id, (int)$currencyId->data); } /** diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.php index 171ea7d0c1..dcdf1301d1 100644 --- a/tests/Unit/Middleware/BinderTest.php +++ b/tests/Unit/Middleware/BinderTest.php @@ -29,10 +29,10 @@ use FireflyIII\Helpers\FiscalHelperInterface; use FireflyIII\Http\Middleware\Binder; use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Support\Collection; +use Log; use Route; use Symfony\Component\HttpFoundation\Response; use Tests\TestCase; -use Log; /** * Class BinderTest @@ -539,8 +539,8 @@ class BinderTest extends TestCase $helper = $this->mock(FiscalHelperInterface::class); $date = new Carbon; - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/20170917'); @@ -556,21 +556,23 @@ class BinderTest extends TestCase { Route::middleware(Binder::class)->any( '/_test/binder/{date}', function (Carbon $date) { + Log::debug(sprintf('Received in function: "%s"', $date->format('Y-m-d'))); + return 'date: ' . $date->format('Y-m-d'); } ); $date = new Carbon; $date->endOfMonth(); + $testDate = clone $date; // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); - + $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/currentMonthEnd'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); - $response->assertSee('date: ' . $date->format('Y-m-d')); + $response->assertSee('date: ' . $testDate->format('Y-m-d')); } /** @@ -586,16 +588,17 @@ class BinderTest extends TestCase ); $date = new Carbon; $date->startOfMonth(); + $testDate = clone $date; // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/currentMonthStart'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); - $response->assertSee('date: ' . $date->format('Y-m-d')); + $response->assertSee('date: ' . $testDate->format('Y-m-d')); } /** @@ -611,16 +614,17 @@ class BinderTest extends TestCase ); $date = new Carbon; $date->endOfYear(); + $testDate = clone $date; // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/currentYearEnd'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); - $response->assertSee('date: ' . $date->format('Y-m-d')); + $response->assertSee('date: ' . $testDate->format('Y-m-d')); } /** @@ -631,6 +635,8 @@ class BinderTest extends TestCase { $date = new Carbon; $date->startOfYear(); + $testDate = clone $date; + Route::middleware(Binder::class)->any( '/_test/binder/{date}', function (Carbon $date) { return 'date: ' . $date->format('Y-m-d'); @@ -639,13 +645,13 @@ class BinderTest extends TestCase // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/currentYearStart'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); - $response->assertSee('date: ' . $date->format('Y-m-d')); + $response->assertSee('date: ' . $testDate->format('Y-m-d')); } /** @@ -662,16 +668,17 @@ class BinderTest extends TestCase $date = new Carbon; $date->endOfYear(); + $testDate = clone $date; // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($testDate)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/currentFiscalYearEnd'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); - $response->assertSee('date: ' . $date->format('Y-m-d')); + $response->assertSee('date: ' . $testDate->format('Y-m-d')); } /** @@ -688,16 +695,17 @@ class BinderTest extends TestCase $date = new Carbon; $date->startOfYear(); + $testDate = clone $date; // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($testDate)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/currentFiscalYearStart'); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); - $response->assertSee('date: ' . $date->format('Y-m-d')); + $response->assertSee('date: ' . $testDate->format('Y-m-d')); } /** @@ -714,8 +722,8 @@ class BinderTest extends TestCase $date = new Carbon; // mock fiscal helper: $helper = $this->mock(FiscalHelperInterface::class); - $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once(); - $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once(); + $helper->shouldReceive('endOfFiscalYear')->andReturn($date)->atLeast()->once(); + $helper->shouldReceive('startOfFiscalYear')->andReturn($date)->atLeast()->once(); $this->be($this->user()); $response = $this->get('/_test/binder/fakedate');