Skip to content

Commit

Permalink
test(phpstan): add annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Jun 4, 2024
1 parent 428cece commit 7fd72c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ parameters:
- tests/src
bootstrapFiles:
- tests/bootstrap.php
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- "#^Call to an undefined method Mockery\\.*#"

Expand Down
3 changes: 3 additions & 0 deletions src/RatingList/RatingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function getRequest(): ?DateTimeImmutable
}


/**
* @return ArrayIterator<string, Property>
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->properties);
Expand Down
7 changes: 5 additions & 2 deletions tests/src/ExchangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use h4kuna\Exchange\RatingList\CacheEntity;
use h4kuna\Exchange\RatingList\RatingList;
use h4kuna\Exchange\RatingList\RatingListCache;
use Mockery\MockInterface;
use Tester\Assert;
use Tester\TestCase;

Expand Down Expand Up @@ -96,13 +97,15 @@ private static function createExchange(): Exchange
'USD' => new Property(10, 135, 'USD'),
]);

$ratingListCache = mock(CacheLocking::class)
->makePartial();
/** @var CacheLocking&MockInterface $ratingListCache */
$ratingListCache = mock(CacheLocking::class);
$ratingListCache->makePartial();
$ratingListCache->shouldReceive('load')
->andReturn(null);
$ratingListCache->shouldReceive('get')
->andReturn($ratingList, $ratingList2);

/** @var SourceDownloadInterface&MockInterface $sourceDownload */
$sourceDownload = mock(SourceDownloadInterface::class);

$ratingListCache = new RatingListCache($ratingListCache, $sourceDownload);
Expand Down
26 changes: 16 additions & 10 deletions tests/src/RatingList/RatingListCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use h4kuna\Exchange\RatingList\CacheEntity;
use h4kuna\Exchange\RatingList\RatingList;
use h4kuna\Exchange\RatingList\RatingListCache;
use Mockery\Mock;
use Mockery\MockInterface;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\SimpleCache\CacheInterface;
use Tester\Assert;
Expand Down Expand Up @@ -70,8 +70,9 @@ public function testRebuild(): void
$ratingList = self::createRatingList();
$ratingList2 = self::createRatingList();

$cacheLocking = mock(CacheLocking::class)
->makePartial();
/** @var MockInterface&CacheLocking $cacheLocking */
$cacheLocking = mock(CacheLocking::class);
$cacheLocking->makePartial();
$cacheLocking->shouldReceive('get')
->with('h4kuna.Exchange.Driver.Cnb.Day.ttl')
->andReturn($ratingList, $ratingList2);
Expand Down Expand Up @@ -148,29 +149,33 @@ public function testFatalFailedBuild(): void


/**
* @return Mock&SourceDownloadInterface
* @return MockInterface&SourceDownloadInterface
*/
private static function createSourceDownload()
{
$source = mock(SourceDownloadInterface::class)
->makePartial();
/** @var MockInterface&SourceDownloadInterface $source */
$source = mock(SourceDownloadInterface::class);
$source->makePartial();

return $source;
}


/**
* @return Mock&CacheInterface
* @return MockInterface&CacheInterface
*/
private static function createCache()
{
return mock(CacheInterface::class)
->makePartial();
/** @var MockInterface&CacheInterface $cache */
$cache = mock(CacheInterface::class);
$cache->makePartial();

return $cache;
}


/**
* @return Mock&CacheLocking
* @return MockInterface&CacheLocking
*/
private static function createCacheLocking(
RatingList $ratingList,
Expand All @@ -189,6 +194,7 @@ private static function createCacheLocking(
return true;
};

/** @var CacheLocking&MockInterface $cacheLocking */
$cacheLocking = mock(CacheLocking::class)
->makePartial();
$cacheLocking->shouldReceive('set')
Expand Down

0 comments on commit 7fd72c9

Please sign in to comment.