|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +namespace SmtpValidatorEmail\Tests\Email; |
| 5 | + |
| 6 | +use SmtpValidatorEmail\Email\EmailBag; |
| 7 | + |
| 8 | +class EmailBagTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + |
| 11 | + public function testConstructorNoArrayGivenDropsError() |
| 12 | + { |
| 13 | + $this->setExpectedException(get_class(new \PHPUnit_Framework_Error("", 0, "", 1))); |
| 14 | + new EmailBag("notAnArrays"); |
| 15 | + } |
| 16 | + |
| 17 | + public function testToStringReturnsString() |
| 18 | + { |
| 19 | + $emails = array ( |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + ); |
| 26 | + |
| 27 | + $bag = new EmailBag($emails); |
| 28 | + $this->assertTrue(is_string($bag->__toString())); |
| 29 | + } |
| 30 | + |
| 31 | + public function testReplaceNoArrayGivenDropsError() |
| 32 | + { |
| 33 | + $this->setExpectedException(get_class(new \PHPUnit_Framework_Error("", 0, "", 1))); |
| 34 | + $bag = new EmailBag(); |
| 35 | + $bag->replace("sdasd"); |
| 36 | + } |
| 37 | + |
| 38 | + public function testGetReturnsProperValue() |
| 39 | + { |
| 40 | + $emails = array ( |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + ); |
| 47 | + |
| 48 | + $bag = new EmailBag($emails); |
| 49 | + $this-> assertEquals( '[email protected]', $bag-> get( 3)); |
| 50 | + } |
| 51 | + |
| 52 | + public function testGetInvalidArgumentKey() |
| 53 | + { |
| 54 | + $this->setExpectedException( |
| 55 | + '\InvalidArgumentException' |
| 56 | + ); |
| 57 | + $bag = new EmailBag(); |
| 58 | + $bag->get(new \stdClass()); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGetWorksWithAssocArray() |
| 62 | + { |
| 63 | + $emails = array ( |
| 64 | + 'codeforges' => '[email protected]', |
| 65 | + |
| 66 | + ); |
| 67 | + |
| 68 | + $bag = new EmailBag($emails); |
| 69 | + $bag->get('codeforges'); |
| 70 | + } |
| 71 | + |
| 72 | + public function testSetInvalidArgumentKey() |
| 73 | + { |
| 74 | + $this->setExpectedException( |
| 75 | + '\InvalidArgumentException' |
| 76 | + ); |
| 77 | + |
| 78 | + $bag = new EmailBag(); |
| 79 | + $bag-> set( new \ stdClass(), '[email protected]'); |
| 80 | + } |
| 81 | + |
| 82 | + public function testSetAcceptsAssocArray() |
| 83 | + { |
| 84 | + $emails = array ( |
| 85 | + 'codeforges' => '[email protected]', |
| 86 | + |
| 87 | + ); |
| 88 | + |
| 89 | + new EmailBag($emails); |
| 90 | + } |
| 91 | + |
| 92 | + public function testHasReturnProperValue() |
| 93 | + { |
| 94 | + $emails = array ( |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + ); |
| 101 | + $bag = new EmailBag($emails); |
| 102 | + $this->assertTrue($bag->has(1)); |
| 103 | + } |
| 104 | + |
| 105 | + public function testHasWorksWithAssocArray() |
| 106 | + { |
| 107 | + $emails = array ( |
| 108 | + 'codeforges' => '[email protected]', |
| 109 | + |
| 110 | + ); |
| 111 | + |
| 112 | + $bag = new EmailBag($emails); |
| 113 | + $this->assertTrue($bag->has('codeforges')); |
| 114 | + } |
| 115 | + |
| 116 | + public function testContainsReturnsPropperValue() |
| 117 | + { |
| 118 | + $emails = array ( |
| 119 | + 'codeforges' => '[email protected]', |
| 120 | + |
| 121 | + ); |
| 122 | + |
| 123 | + $bag = new EmailBag($emails); |
| 124 | + $this-> assertTrue( $bag-> contains( 'codeforges', '[email protected]')); |
| 125 | + } |
| 126 | + |
| 127 | + public function testRemove() |
| 128 | + { |
| 129 | + $emails = array ( |
| 130 | + 'codeforges' => '[email protected]', |
| 131 | + |
| 132 | + ); |
| 133 | + |
| 134 | + $bag = new EmailBag($emails); |
| 135 | + $beforeRemoveEmails = $bag->all(); |
| 136 | + $bag->remove('codeforges'); |
| 137 | + $this->assertNotEquals($beforeRemoveEmails, $bag->all()); |
| 138 | + } |
| 139 | + |
| 140 | + public function testReplace() |
| 141 | + { |
| 142 | + $emails = array ( |
| 143 | + 'codeforges' => '[email protected]', |
| 144 | + |
| 145 | + ); |
| 146 | + |
| 147 | + $replaceEmails = array ( |
| 148 | + 'traceweb' => '[email protected]', |
| 149 | + 'codeforges' => '[email protected]' |
| 150 | + ); |
| 151 | + |
| 152 | + $bag = new EmailBag($emails); |
| 153 | + $oldEmails = $bag->all(); |
| 154 | + $bag->replace($replaceEmails); |
| 155 | + $replaceEmails = $bag->all(); |
| 156 | + |
| 157 | + $this->assertNotTrue($oldEmails === $replaceEmails); |
| 158 | + } |
| 159 | + |
| 160 | + public function testGetIteratorIsObject(){ |
| 161 | + $emails = array ( |
| 162 | + 'codeforges' => '[email protected]', |
| 163 | + |
| 164 | + ); |
| 165 | + $bag = new EmailBag($emails); |
| 166 | + |
| 167 | + $this->assertTrue( is_object($bag->getIterator()) ); |
| 168 | + } |
| 169 | +} |
0 commit comments