1<?php
2
3/*
4 * This file is part of Respect/Validation.
5 *
6 * (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
7 *
8 * For the full copyright and license information, please view the "LICENSE.md"
9 * file that was distributed with this source code.
10 */
11
12namespace Respect\Validation\Rules;
13
14/**
15 * @group  rule
16 * @covers Respect\Validation\Rules\Multiple
17 * @covers Respect\Validation\Exceptions\MultipleException
18 */
19class MultipleTest extends \PHPUnit_Framework_TestCase
20{
21    /**
22     * @dataProvider providerForMultiple
23     */
24    public function testValidNumberMultipleOf($multipleOf, $input)
25    {
26        $multiple = new Multiple($multipleOf);
27        $this->assertTrue($multiple->validate($input));
28        $this->assertTrue($multiple->assert($input));
29        $this->assertTrue($multiple->check($input));
30    }
31
32    /**
33     * @dataProvider providerForNotMultiple
34     * @expectedException Respect\Validation\Exceptions\MultipleException
35     */
36    public function testNotMultipleShouldThrowMultipleException($multipleOf, $input)
37    {
38        $multiple = new Multiple($multipleOf);
39        $this->assertFalse($multiple->validate($input));
40        $this->assertFalse($multiple->assert($input));
41    }
42
43    public function providerForMultiple()
44    {
45        return [
46            ['', ''],
47            [5, 20],
48            [5, 5],
49            [5, 0],
50            [5, -500],
51            [1, 0],
52            [1, 1],
53            [1, 2],
54            [1, 3],
55            [0, 0], // Only 0 is multiple of 0
56        ];
57    }
58
59    public function providerForNotMultiple()
60    {
61        return [
62            [5, 11],
63            [5, 3],
64            [5, -1],
65            [3, 4],
66            [10, -8],
67            [10, 57],
68            [10, 21],
69            [0, 1],
70            [0, 2],
71        ];
72    }
73}
74