| 54 | | public function testValue() |
|---|
| 55 | | { |
|---|
| 56 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| 57 | | $this->assertEqual($floatFilter->execute('8.4533'), 8453); |
|---|
| 58 | | $this->assertEqual($floatFilter->execute('8.4538'), 8453); |
|---|
| 59 | | $this->assertEqual($floatFilter->execute('8.45'), 8450); |
|---|
| 60 | | $this->assertEqual($floatFilter->execute('8'), 8000); |
|---|
| 61 | | $this->assertEqual($floatFilter->execute(8.4533), 8453); |
|---|
| 62 | | $this->assertEqual($floatFilter->execute(8.4538), 8453); |
|---|
| 63 | | $this->assertEqual($floatFilter->execute(8.45), 8450); |
|---|
| 64 | | $this->assertEqual($floatFilter->execute(8), 8000); |
|---|
| 65 | | } |
|---|
| | 54 | public function testValue() |
|---|
| | 55 | { |
|---|
| | 56 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| | 57 | $this->assertEqual($floatFilter->execute('8.4533'), 8453); |
|---|
| | 58 | $this->assertEqual($floatFilter->execute('8.4538'), 8453); |
|---|
| | 59 | $this->assertEqual($floatFilter->execute('8.45'), 8450); |
|---|
| | 60 | $this->assertEqual($floatFilter->execute('8'), 8000); |
|---|
| | 61 | $this->assertEqual($floatFilter->execute(8.4533), 8453); |
|---|
| | 62 | $this->assertEqual($floatFilter->execute(8.4538), 8453); |
|---|
| | 63 | $this->assertEqual($floatFilter->execute(8.45), 8450); |
|---|
| | 64 | $this->assertEqual($floatFilter->execute(8), 8000); |
|---|
| | 65 | } |
|---|
| 71 | | public function testWithUnsetWhenRequired() |
|---|
| 72 | | { |
|---|
| 73 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| 74 | | $floatFilter->setRequired(true); |
|---|
| 75 | | $this->assertEqual($floatFilter->execute(true), 1000); |
|---|
| 76 | | $this->assertEqual($floatFilter->execute(false), 0); |
|---|
| 77 | | $this->expectException('stubFilterException'); |
|---|
| 78 | | $floatFilter->execute(null); |
|---|
| 79 | | } |
|---|
| 80 | | |
|---|
| 81 | | /** |
|---|
| | 71 | public function testWithUnsetWhenRequired() |
|---|
| | 72 | { |
|---|
| | 73 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| | 74 | $floatFilter->setRequired(true); |
|---|
| | 75 | $this->assertEqual($floatFilter->execute(true), 1000); |
|---|
| | 76 | $this->assertEqual($floatFilter->execute(false), 0); |
|---|
| | 77 | $this->expectException('stubFilterException'); |
|---|
| | 78 | $floatFilter->execute(null); |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| | 81 | /** |
|---|
| 85 | | public function testWithUnsetEmptyStringWhenRequired() |
|---|
| 86 | | { |
|---|
| 87 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| 88 | | $floatFilter->setRequired(true); |
|---|
| 89 | | $this->expectException('stubFilterException'); |
|---|
| 90 | | $floatFilter->execute(''); |
|---|
| 91 | | } |
|---|
| | 85 | public function testWithUnsetEmptyStringWhenRequired() |
|---|
| | 86 | { |
|---|
| | 87 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| | 88 | $floatFilter->setRequired(true); |
|---|
| | 89 | $this->expectException('stubFilterException'); |
|---|
| | 90 | $floatFilter->execute(''); |
|---|
| | 91 | } |
|---|
| 97 | | public function testUnsetWhenNotRequired() |
|---|
| 98 | | { |
|---|
| 99 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| 100 | | $floatFilter->setRequired(false); |
|---|
| 101 | | $this->assertEqual($floatFilter->execute(null), 0); |
|---|
| 102 | | $this->assertEqual($floatFilter->execute(''), 0); |
|---|
| 103 | | $this->assertEqual($floatFilter->execute(true), 1000); |
|---|
| 104 | | $this->assertEqual($floatFilter->execute(false), 0); |
|---|
| 105 | | } |
|---|
| | 97 | public function testUnsetWhenNotRequired() |
|---|
| | 98 | { |
|---|
| | 99 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| | 100 | $floatFilter->setRequired(false); |
|---|
| | 101 | $this->assertEqual($floatFilter->execute(null), 0); |
|---|
| | 102 | $this->assertEqual($floatFilter->execute(''), 0); |
|---|
| | 103 | $this->assertEqual($floatFilter->execute(true), 1000); |
|---|
| | 104 | $this->assertEqual($floatFilter->execute(false), 0); |
|---|
| | 105 | } |
|---|
| 110 | | public function testWithMinValidator() |
|---|
| 111 | | { |
|---|
| 112 | | $this->mockStubValidatorMin->setReturnValueAt(0, 'validate', true); |
|---|
| 113 | | $this->mockStubValidatorMin->setReturnValueAt(1, 'validate', false); |
|---|
| 114 | | $this->mockStubValidatorMin->setReturnValue('getCriteria', array()); |
|---|
| 115 | | |
|---|
| 116 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, $this->mockStubValidatorMin); |
|---|
| 117 | | $this->assertEqual($floatFilter->execute(-10), -10000); |
|---|
| 118 | | $this->expectException('stubFilterException'); |
|---|
| 119 | | $floatFilter->execute(-11); |
|---|
| 120 | | } |
|---|
| | 110 | public function testWithMinValidator() |
|---|
| | 111 | { |
|---|
| | 112 | $this->mockStubValidatorMin->setReturnValueAt(0, 'validate', true); |
|---|
| | 113 | $this->mockStubValidatorMin->setReturnValueAt(1, 'validate', false); |
|---|
| | 114 | $this->mockStubValidatorMin->setReturnValue('getCriteria', array()); |
|---|
| | 115 | |
|---|
| | 116 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, $this->mockStubValidatorMin); |
|---|
| | 117 | $this->assertEqual($floatFilter->execute(-10), -10000); |
|---|
| | 118 | $this->expectException('stubFilterException'); |
|---|
| | 119 | $floatFilter->execute(-11); |
|---|
| | 120 | } |
|---|
| 125 | | public function testWithMaxValidator() |
|---|
| 126 | | { |
|---|
| 127 | | $this->mockStubValidatorMax->setReturnValueAt(0, 'validate', true); |
|---|
| 128 | | $this->mockStubValidatorMax->setReturnValueAt(1, 'validate', false); |
|---|
| 129 | | $this->mockStubValidatorMax->setReturnValue('getCriteria', array()); |
|---|
| 130 | | |
|---|
| 131 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, null, $this->mockStubValidatorMax); |
|---|
| 132 | | $this->assertEqual($floatFilter->execute(10), 10000); |
|---|
| 133 | | $this->expectException('stubFilterException'); |
|---|
| 134 | | $floatFilter->execute(11); |
|---|
| 135 | | } |
|---|
| | 125 | public function testWithMaxValidator() |
|---|
| | 126 | { |
|---|
| | 127 | $this->mockStubValidatorMax->setReturnValueAt(0, 'validate', true); |
|---|
| | 128 | $this->mockStubValidatorMax->setReturnValueAt(1, 'validate', false); |
|---|
| | 129 | $this->mockStubValidatorMax->setReturnValue('getCriteria', array()); |
|---|
| | 130 | |
|---|
| | 131 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, null, $this->mockStubValidatorMax); |
|---|
| | 132 | $this->assertEqual($floatFilter->execute(10), 10000); |
|---|
| | 133 | $this->expectException('stubFilterException'); |
|---|
| | 134 | $floatFilter->execute(11); |
|---|
| | 135 | } |
|---|
| 139 | | public function testFloat() |
|---|
| 140 | | { |
|---|
| 141 | | stubRegistry::setConfig('core.number.decimals', 2); |
|---|
| 142 | | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| 143 | | $this->assertEqual($floatFilter->execute('1.564'), 156); |
|---|
| 144 | | } |
|---|
| | 139 | public function testFloat() |
|---|
| | 140 | { |
|---|
| | 141 | stubRegistry::setConfig('net.stubbles.number.decimals', 2); |
|---|
| | 142 | $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); |
|---|
| | 143 | $this->assertEqual($floatFilter->execute('1.564'), 156); |
|---|
| | 144 | } |
|---|