Skip to content

Commit

Permalink
Merge pull request #299 from acelaya/feature/repository-tests
Browse files Browse the repository at this point in the history
Improved repository tests
  • Loading branch information
acelaya authored Dec 2, 2018
2 parents d492489 + 3faf6e9 commit 6ba4d8e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
## 1.15.0 - 2018-12-02

#### Added

Expand All @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

* [#267](https://github.com/shlinkio/shlink/issues/267) API responses and the CLI interface is no longer translated and uses english always. Only not found error templates are still translated.
* [#289](https://github.com/shlinkio/shlink/issues/289) Extracted coding standard rules to a separated package.
* [#273](https://github.com/shlinkio/shlink/issues/273) Improved code coverage in repository classes.

#### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

"test:pretty": [
"@test",
"phpcov merge build --html build/html"
"phpdbg -qrr vendor/bin/phpcov merge build --html build/html"
],
"test:unit:pretty": "phpdbg -qrr vendor/bin/phpunit --coverage-html build/coverage --order-by=random",

Expand Down
7 changes: 7 additions & 0 deletions indocker
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#!/usr/bin/env bash

# Run docker containers if they are not up yet
if [[ $(docker ps | grep shlink_swoole) ]]; then :
else
docker-compose up -d
fi

docker exec -it shlink_swoole /bin/sh -c "$*"
2 changes: 1 addition & 1 deletion module/Core/src/Repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TagRepository extends EntityRepository implements TagRepositoryInterface
* @param array $names
* @return int The number of affected entries
*/
public function deleteByName(array $names)
public function deleteByName(array $names): int
{
if (empty($names)) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion module/Core/src/Repository/TagRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface TagRepositoryInterface extends ObjectRepository
* @param array $names
* @return int The number of affected entries
*/
public function deleteByName(array $names);
public function deleteByName(array $names): int;
}
21 changes: 20 additions & 1 deletion module/Core/test-func/Repository/ShortUrlRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public function findListProperlyFiltersByTagAndSearchTerm()
$this->getEntityManager()->persist($foo);

$bar = new ShortUrl('bar');
$bar->setShortCode('bar_very_long_text');
$visit = new Visit($bar, Visitor::emptyInstance());
$this->getEntityManager()->persist($visit);
$bar->setShortCode('bar_very_long_text')
->setVisits(new ArrayCollection([$visit]));
$this->getEntityManager()->persist($bar);

$foo2 = new ShortUrl('foo_2');
Expand All @@ -104,6 +107,22 @@ public function findListProperlyFiltersByTagAndSearchTerm()
$result = $this->repo->findList(null, null, 'foo', ['bar']);
$this->assertCount(1, $result);
$this->assertSame($foo, $result[0]);

$result = $this->repo->findList();
$this->assertCount(3, $result);

$result = $this->repo->findList(2);
$this->assertCount(2, $result);

$result = $this->repo->findList(2, 1);
$this->assertCount(2, $result);

$result = $this->repo->findList(2, 2);
$this->assertCount(1, $result);

$result = $this->repo->findList(null, null, null, [], ['visits' => 'DESC']);
$this->assertCount(3, $result);
$this->assertSame($bar, $result[0]);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions module/Core/test-func/Repository/VisitRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function findVisitsByShortCodeReturnsProperData()
$this->assertCount(4, $this->repo->findVisitsByShortCode($shortUrl->getShortCode(), new DateRange(
Chronos::parse('2016-01-03')
)));
$this->assertCount(3, $this->repo->findVisitsByShortCode($shortUrl->getShortCode(), null, 3, 2));
$this->assertCount(2, $this->repo->findVisitsByShortCode($shortUrl->getShortCode(), null, 5, 4));
}

/**
Expand Down

0 comments on commit 6ba4d8e

Please sign in to comment.