Skip to content

Commit

Permalink
Merge pull request #9 from ARCANEDEV/patch-1
Browse files Browse the repository at this point in the history
Updating the package
  • Loading branch information
arcanedev-maroc authored Feb 18, 2018
2 parents d5ccf5f + 3846725 commit 6e7fb3b
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 105 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
"laravel": {
"providers": [
"Arcanedev\\SpamBlocker\\SpamBlockerServiceProvider"
],
"aliases": {
"SpamBlocker": "Arcanedev\\SpamBlocker\\Facades\\SpamBlocker"
}
]
}
}
}
4 changes: 1 addition & 3 deletions src/Entities/SpammerCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ private function addOne($host, $blocked = true)
{
$spammer = Spammer::make($host, $blocked);

$this->put($spammer->host(), $spammer);

return $this;
return $this->put($spammer->host(), $spammer);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/SpamBlocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Arcanedev\SpamBlocker\Entities\SpammerCollection;
use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;

/**
* Class SpamBlocker
Expand Down Expand Up @@ -341,7 +340,7 @@ private function getRootDomain($domain)
*/
protected function resetCache()
{
Cache::forget($this->cacheKey);
cache()->forget($this->cacheKey);

return $this;
}
Expand All @@ -355,7 +354,7 @@ protected function resetCache()
*/
private function cacheSpammers(Closure $callback)
{
return Cache::remember($this->cacheKey, $this->cacheExpires, $callback);
return cache()->remember($this->cacheKey, $this->cacheExpires, $callback);
}

/**
Expand Down
48 changes: 24 additions & 24 deletions tests/Entities/SpammerCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function it_can_be_instantiated()
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $this->spammers);
static::assertInstanceOf($expected, $this->spammers);
}
}

Expand All @@ -67,11 +67,11 @@ public function it_can_load_spammers()

$this->spammers = SpammerCollection::load($spammers);

$this->assertCount(count($spammers), $this->spammers);
static::assertCount(count($spammers), $this->spammers);

foreach ($this->spammers as $spammer) {
$this->assertTrue(in_array($spammer->host(), $spammers));
$this->assertTrue($spammer->isBlocked());
static::assertTrue(in_array($spammer->host(), $spammers));
static::assertTrue($spammer->isBlocked());
}
}

Expand All @@ -82,12 +82,12 @@ public function it_can_add_one_to_blacklist()

$this->spammers->blockOne($host);

$this->assertTrue($this->spammers->exists($host));
static::assertTrue($this->spammers->exists($host));

$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertTrue($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertTrue($spammer->isBlocked());
}

/** @test */
Expand All @@ -102,12 +102,12 @@ public function it_can_add_many_to_blacklist()
$this->spammers->includes($spammers);

foreach ($spammers as $host) {
$this->assertTrue($this->spammers->exists($host));
static::assertTrue($this->spammers->exists($host));

$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertTrue($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertTrue($spammer->isBlocked());
}
}

Expand All @@ -118,12 +118,12 @@ public function it_can_add_one_to_whitelist()

$this->spammers->allowOne($host);

$this->assertTrue($this->spammers->exists($host));
static::assertTrue($this->spammers->exists($host));

$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertFalse($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertFalse($spammer->isBlocked());
}

/** @test */
Expand All @@ -138,12 +138,12 @@ public function it_can_add_many_to_whitelist()
$this->spammers->excludes($spammers);

foreach ($spammers as $host) {
$this->assertTrue($this->spammers->exists($host));
static::assertTrue($this->spammers->exists($host));

$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertFalse($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertFalse($spammer->isBlocked());
}
}

Expand All @@ -155,14 +155,14 @@ public function it_can_block_and_allow_a_host()
$this->spammers->blockOne($host);
$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertTrue($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertTrue($spammer->isBlocked());

$this->spammers->allowOne($host);
$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertFalse($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertFalse($spammer->isBlocked());
}

/** @test */
Expand All @@ -173,13 +173,13 @@ public function it_can_allow_and_block_a_host()
$this->spammers->allowOne($host);
$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertFalse($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertFalse($spammer->isBlocked());

$this->spammers->blockOne($host);
$spammer = $this->spammers->getOne($host);

$this->assertSame($host, $spammer->host());
$this->assertTrue($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertTrue($spammer->isBlocked());
}
}
28 changes: 14 additions & 14 deletions tests/Entities/SpammerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,54 @@ public function it_can_be_instantiated()
{
$spammer = $this->createBadSpammer();

$this->assertSame('http://bad-spammer.xyz', $spammer->host());
$this->assertTrue($spammer->isBlocked());
static::assertSame('http://bad-spammer.xyz', $spammer->host());
static::assertTrue($spammer->isBlocked());
}

/** @test */
public function it_can_convert_to_array()
{
$spammer = $this->createBadSpammer();

$this->assertInstanceOf(\Illuminate\Contracts\Support\Arrayable::class, $spammer);
static::assertInstanceOf(\Illuminate\Contracts\Support\Arrayable::class, $spammer);

$array = $spammer->toArray();

$this->assertInternalType('array', $array);
$this->assertArrayHasKey('host', $array);
$this->assertArrayHasKey('blocked', $array);
$this->assertEquals($spammer->host(), $array['host']);
$this->assertEquals($spammer->isBlocked(), $array['blocked']);
static::assertInternalType('array', $array);
static::assertArrayHasKey('host', $array);
static::assertArrayHasKey('blocked', $array);
static::assertEquals($spammer->host(), $array['host']);
static::assertEquals($spammer->isBlocked(), $array['blocked']);
}

/** @test */
public function it_can_convert_to_json()
{
$spammer = $this->createBadSpammer();

$this->assertInstanceOf(\Illuminate\Contracts\Support\Jsonable::class, $spammer);
static::assertInstanceOf(\Illuminate\Contracts\Support\Jsonable::class, $spammer);

$json = $spammer->toJson();

$this->assertJson($json);
static::assertJson($json);
}

/** @test */
public function it_can_make()
{
$spammer = Spammer::make($url = 'http://google.com', false);

$this->assertSame($url, $spammer->host());
$this->assertFalse($spammer->isBlocked());
static::assertSame($url, $spammer->host());
static::assertFalse($spammer->isBlocked());
}

/** @test */
public function it_can_check_if_has_same_host_url()
{
$spammer = $this->createBadSpammer();

$this->assertTrue($spammer->isSameHost('http://bad-spammer.xyz'));
$this->assertFalse($spammer->isSameHost('http://google.com'));
static::assertTrue($spammer->isSameHost('http://bad-spammer.xyz'));
static::assertFalse($spammer->isSameHost('http://google.com'));
}

/* -----------------------------------------------------------------
Expand Down
52 changes: 26 additions & 26 deletions tests/Facades/SpamBlockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ public function it_can_get_spammers()
{
$spammers = SpamBlocker::spammers();

$this->assertInstanceOf(
static::assertInstanceOf(
\Arcanedev\SpamBlocker\Entities\SpammerCollection::class,
$spammers
);

$this->assertTrue($spammers->count() > 400);
static::assertTrue($spammers->count() > 400);
}

/** @test */
public function it_can_set_and_get_includes()
{
$this->assertEmpty(SpamBlocker::getIncludes());
static::assertEmpty(SpamBlocker::getIncludes());

$includes = [
'evil-spammer.io',
Expand All @@ -41,14 +41,14 @@ public function it_can_set_and_get_includes()

SpamBlocker::setIncludes($includes);

$this->assertCount(count($includes), SpamBlocker::getIncludes());
$this->assertSame($includes, SpamBlocker::getIncludes());
static::assertCount(count($includes), SpamBlocker::getIncludes());
static::assertSame($includes, SpamBlocker::getIncludes());
}

/** @test */
public function it_can_set_and_get_excludes()
{
$this->assertEmpty(SpamBlocker::getExcludes());
static::assertEmpty(SpamBlocker::getExcludes());

$excludes = [
'google.com',
Expand All @@ -58,8 +58,8 @@ public function it_can_set_and_get_excludes()

SpamBlocker::setExcludes($excludes);

$this->assertCount(count($excludes), SpamBlocker::getExcludes());
$this->assertSame($excludes, SpamBlocker::getExcludes());
static::assertCount(count($excludes), SpamBlocker::getExcludes());
static::assertSame($excludes, SpamBlocker::getExcludes());
}

/** @test */
Expand All @@ -69,7 +69,7 @@ public function it_can_include_a_new_spammer_to_blacklist()

SpamBlocker::block('new-spammer.com');

$this->assertNotEquals($spammers->count(), SpamBlocker::all()->count());
static::assertNotEquals($spammers->count(), SpamBlocker::all()->count());
}

/** @test */
Expand All @@ -80,12 +80,12 @@ public function it_can_skip_adding_existing_spammer_in_blacklist()

SpamBlocker::block($host);

$this->assertCount($spammers->count(), SpamBlocker::all());
static::assertCount($spammers->count(), SpamBlocker::all());

$spammer = SpamBlocker::getSpammer($host);

$this->assertSame($host, $spammer->host());
$this->assertTrue($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertTrue($spammer->isBlocked());
}

/** @test */
Expand All @@ -96,12 +96,12 @@ public function it_can_exclude_a_new_spammer_from_blacklist()

SpamBlocker::allow($host);

$this->assertNotEquals($spammers->count(), SpamBlocker::all()->count());
static::assertNotEquals($spammers->count(), SpamBlocker::all()->count());

$spammer = SpamBlocker::getSpammer($host);

$this->assertSame($host, $spammer->host());
$this->assertFalse($spammer->isBlocked());
static::assertSame($host, $spammer->host());
static::assertFalse($spammer->isBlocked());
}

/** @test */
Expand All @@ -111,7 +111,7 @@ public function it_can_set_and_get_source()

SpamBlocker::setSource($path);

$this->assertSame($path, SpamBlocker::getSource());
static::assertSame($path, SpamBlocker::getSource());
}

/**
Expand All @@ -130,17 +130,17 @@ public function it_can_check_is_blocked()
{
$host = 'http://0n-line.tv';

$this->assertTrue(SpamBlocker::isBlocked($host));
$this->assertFalse(SpamBlocker::isAllowed($host));
static::assertTrue(SpamBlocker::isBlocked($host));
static::assertFalse(SpamBlocker::isAllowed($host));
}

/** @test */
public function it_can_check_is_allowed()
{
$host = 'http://google.com';

$this->assertTrue(SpamBlocker::isAllowed($host));
$this->assertFalse(SpamBlocker::isBlocked($host));
static::assertTrue(SpamBlocker::isAllowed($host));
static::assertFalse(SpamBlocker::isBlocked($host));
}

/** @test */
Expand All @@ -151,14 +151,14 @@ public function it_can_reset()
SpamBlocker::block('http://0n-line.tv');
SpamBlocker::allow('http://google.com');

$this->assertCount(1, SpamBlocker::getExcludes());
$this->assertCount(1, SpamBlocker::getIncludes());
$this->assertCount($count + 2, SpamBlocker::all());
static::assertCount(1, SpamBlocker::getExcludes());
static::assertCount(1, SpamBlocker::getIncludes());
static::assertCount($count + 2, SpamBlocker::all());

SpamBlocker::reset();

$this->assertEmpty(SpamBlocker::getExcludes());
$this->assertEmpty(SpamBlocker::getIncludes());
$this->assertCount($count, SpamBlocker::all());
static::assertEmpty(SpamBlocker::getExcludes());
static::assertEmpty(SpamBlocker::getIncludes());
static::assertCount($count, SpamBlocker::all());
}
}
Loading

0 comments on commit 6e7fb3b

Please sign in to comment.