Fix test coverage. [skip ci]

This commit is contained in:
James Cole 2019-02-02 09:53:19 +01:00
parent 384e64d94d
commit 1d73ff7c13
4 changed files with 37 additions and 27 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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');