mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-03-13 05:26:57 +00:00
Add basic methods
This commit is contained in:
parent
c5b260f298
commit
792bfda017
|
@ -9,7 +9,8 @@
|
|||
"email": "oliver@oliverdavies.uk"
|
||||
}
|
||||
],
|
||||
"require": {},
|
||||
"require": {
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7"
|
||||
},
|
||||
|
|
52
src/Filter.php
Normal file
52
src/Filter.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder;
|
||||
|
||||
class Filter
|
||||
{
|
||||
public function has($value)
|
||||
{
|
||||
return ['hasTheWord' => $value];
|
||||
}
|
||||
|
||||
public function from()
|
||||
{
|
||||
return ['from' => func_get_args()];
|
||||
}
|
||||
|
||||
public function label($label)
|
||||
{
|
||||
return ['label' => $label];
|
||||
}
|
||||
|
||||
public function archive()
|
||||
{
|
||||
return ['shouldArchive' => 'true'];
|
||||
}
|
||||
|
||||
public function labelAndArchive($label)
|
||||
{
|
||||
return $this->label($label) + $this->archive();
|
||||
}
|
||||
|
||||
public function spam()
|
||||
{
|
||||
return [
|
||||
'shouldSpam' => 'true',
|
||||
'shouldNeverSpam' => 'false',
|
||||
];
|
||||
}
|
||||
|
||||
public function neverSpam()
|
||||
{
|
||||
return [
|
||||
'shouldSpam' => 'false',
|
||||
'shouldNeverSpam' => 'true',
|
||||
];
|
||||
}
|
||||
|
||||
public function trash()
|
||||
{
|
||||
return ['shouldTrash' => 'true'];
|
||||
}
|
||||
}
|
121
tests/Unit/FilterTest.php
Normal file
121
tests/Unit/FilterTest.php
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\Tests\GmailFilterBuilder;
|
||||
|
||||
use Opdavies\GmailFilterBuilder\Filter;
|
||||
|
||||
class FilterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Filter
|
||||
*/
|
||||
private $filter;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->filter = new Filter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::has()
|
||||
*/
|
||||
public function testHas()
|
||||
{
|
||||
$this->assertEquals(
|
||||
['hasTheWord' => 'something'],
|
||||
$this->filter->has('something')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::from()
|
||||
*/
|
||||
public function testFrom()
|
||||
{
|
||||
// Ensure that we can set one from address.
|
||||
$this->assertEquals(
|
||||
['from' => ['foo@example.com']],
|
||||
$this->filter->from('foo@example.com')
|
||||
);
|
||||
|
||||
// Ensure that we can set multiple from addresses.
|
||||
$this->assertEquals(
|
||||
['from' => ['foo@example.com', 'bar@example.com']],
|
||||
$this->filter->from('foo@example.com', 'bar@example.com')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::label()
|
||||
*/
|
||||
public function testLabel()
|
||||
{
|
||||
$this->assertEquals(['label' => 'Foo'], $this->filter->label('Foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::archive()
|
||||
*/
|
||||
public function testArchive()
|
||||
{
|
||||
$this->assertEquals(
|
||||
['shouldArchive' => 'true'],
|
||||
$this->filter->archive()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::labelAndArchive()
|
||||
*/
|
||||
public function testLabelAndArchive()
|
||||
{
|
||||
$this->assertEquals(
|
||||
['shouldArchive' => 'true', 'label' => 'Foo'],
|
||||
$this->filter->labelAndArchive('Foo')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::spam()
|
||||
*/
|
||||
public function testSpam()
|
||||
{
|
||||
$this->assertEquals(
|
||||
[
|
||||
'shouldSpam' => 'true',
|
||||
'shouldNeverSpam' => 'false'
|
||||
],
|
||||
$this->filter->spam()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::neverSpam()
|
||||
*/
|
||||
public function testNeverSpam()
|
||||
{
|
||||
$this->assertEquals(
|
||||
[
|
||||
'shouldSpam' => 'false',
|
||||
'shouldNeverSpam' => 'true'
|
||||
],
|
||||
$this->filter->neverSpam()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Filter::trash()
|
||||
*/
|
||||
public function testTrash()
|
||||
{
|
||||
$this->assertEquals(
|
||||
['shouldTrash' => 'true'],
|
||||
$this->filter->trash()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue