|
| 1 | +<?php |
| 2 | +namespace LoggingTest; |
| 3 | + |
| 4 | +use Logging\Logging; |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +class LoggingTest extends TestCase |
| 8 | +{ |
| 9 | + |
| 10 | + |
| 11 | + protected $Logger; |
| 12 | + protected $Loggertest; |
| 13 | + /** |
| 14 | + * Set up. |
| 15 | + */ |
| 16 | + public function setUp() |
| 17 | + { |
| 18 | + parent::setUp(); |
| 19 | + } |
| 20 | + /** |
| 21 | + * @expectedException Exception |
| 22 | + */ |
| 23 | + public function testConnectionInvalidHost() |
| 24 | + { |
| 25 | + $this->Loggertest = Logging::getInstance(); |
| 26 | + $this->Loggertest->setRabbitmqHost("192.168.0.4"); |
| 27 | + $this->Loggertest->setRabbitmqPort("5672"); |
| 28 | + $this->Loggertest->setRabbitmqUser("guest"); |
| 29 | + $this->Loggertest->setRabbitmqPassword("guest"); |
| 30 | + $this->Loggertest->setLoggerTimeFormat("time.RFC3339"); |
| 31 | + $this->Loggertest->setQueuePrefix("ayopop"); |
| 32 | + $this->Loggertest->setQueueNames(array( |
| 33 | + "Api" => "api", |
| 34 | + "Debug" => "debug", |
| 35 | + "Info" => "info", |
| 36 | + "Warn" => "warning", |
| 37 | + "Error" => "error", |
| 38 | + "Critical" => "critical" |
| 39 | + )); |
| 40 | + |
| 41 | + $this->Loggertest->connect(); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @expectedException Exception |
| 46 | + */ |
| 47 | + public function testConnectionInvalidPort() |
| 48 | + { |
| 49 | + $this->Loggertest = Logging::getInstance(); |
| 50 | + $this->Loggertest->setRabbitmqHost("127.0.0.1"); |
| 51 | + $this->Loggertest->setRabbitmqPort("56720"); |
| 52 | + $this->Loggertest->setRabbitmqUser("guest"); |
| 53 | + $this->Loggertest->setRabbitmqPassword("guest"); |
| 54 | + $this->Loggertest->setLoggerTimeFormat("time.RFC3339"); |
| 55 | + $this->Loggertest->setQueuePrefix("ayopop"); |
| 56 | + $this->Loggertest->setQueueNames(array( |
| 57 | + "Api" => "api", |
| 58 | + "Debug" => "debug", |
| 59 | + "Info" => "info", |
| 60 | + "Warn" => "warning", |
| 61 | + "Error" => "error", |
| 62 | + "Critical" => "critical" |
| 63 | + )); |
| 64 | + |
| 65 | + $this->Loggertest->connect(); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @expectedException Exception |
| 70 | + */ |
| 71 | + public function testConnectionInvalidUser() |
| 72 | + { |
| 73 | + $this->Loggertest = Logging::getInstance(); |
| 74 | + $this->Loggertest->setRabbitmqHost("127.0.0.1"); |
| 75 | + $this->Loggertest->setRabbitmqPort("5672"); |
| 76 | + $this->Loggertest->setRabbitmqUser("saurav"); |
| 77 | + $this->Loggertest->setRabbitmqPassword("guest"); |
| 78 | + $this->Loggertest->setLoggerTimeFormat("time.RFC3339"); |
| 79 | + $this->Loggertest->setQueuePrefix("ayopop"); |
| 80 | + $this->Loggertest->setQueueNames(array( |
| 81 | + "Api" => "api", |
| 82 | + "Debug" => "debug", |
| 83 | + "Info" => "info", |
| 84 | + "Warn" => "warning", |
| 85 | + "Error" => "error", |
| 86 | + "Critical" => "critical" |
| 87 | + )); |
| 88 | + |
| 89 | + $this->Loggertest->connect(); |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + public function testConnectionInvalidQueueName() |
| 94 | + { |
| 95 | + try { |
| 96 | + $this->Loggertest = Logging::getInstance(); |
| 97 | + $this->Loggertest->setRabbitmqHost("127.0.0.1"); |
| 98 | + $this->Loggertest->setRabbitmqPort("5672"); |
| 99 | + $this->Loggertest->setRabbitmqUser("guest"); |
| 100 | + $this->Loggertest->setRabbitmqPassword("guest"); |
| 101 | + $this->Loggertest->setLoggerTimeFormat("time.RFC3339"); |
| 102 | + $this->Loggertest->setQueuePrefix("ayopop"); |
| 103 | + $this->Loggertest->setQueueNames(array( |
| 104 | + "Api" => "api", |
| 105 | + "Debug" => "debug", |
| 106 | + "Info" => "info", |
| 107 | + "Warn" => "warning", |
| 108 | + "Error" => "error", |
| 109 | + //"Critical" => "critical" |
| 110 | + )); |
| 111 | + $this->Loggertest->connect(); |
| 112 | + } catch (\Exception $e) { |
| 113 | + $emess = $e->getMessage(); |
| 114 | + // echo $emess; |
| 115 | + } |
| 116 | + $this->assertEquals($emess, 'Parameter Mismatch'); |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + public function testGetInstance() |
| 121 | + { |
| 122 | + $Logger = Logging::getInstance(); |
| 123 | + $Logger->setRabbitmqHost("127.0.0.1"); |
| 124 | + $Logger->setRabbitmqPort("5672"); |
| 125 | + $Logger->setRabbitmqUser("guest"); |
| 126 | + $Logger->setRabbitmqPassword("guest"); |
| 127 | + $Logger->setLoggerTimeFormat("time.RFC3339"); |
| 128 | + $Logger->setQueuePrefix("ayopop"); |
| 129 | + $Logger->setQueueNames(array( |
| 130 | + "Api" => "api", |
| 131 | + "Debug" => "debug", |
| 132 | + "Info" => "info", |
| 133 | + "Warn" => "warning", |
| 134 | + "Error" => "error", |
| 135 | + "Critical" => "critical" |
| 136 | + )); |
| 137 | + |
| 138 | + $Logger->connect(); |
| 139 | + $first = $Logger; |
| 140 | + $second = Logging::getInstance(); |
| 141 | + $this->assertSame($first, $second); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @expectedException \ArgumentCountError |
| 146 | + */ |
| 147 | + public function testpublishMessage() |
| 148 | + { |
| 149 | + |
| 150 | + $Logger = Logging::getInstance(); |
| 151 | + $Logger->setRabbitmqHost("127.0.0.1"); |
| 152 | + $Logger->setRabbitmqPort("5672"); |
| 153 | + $Logger->setRabbitmqUser("guest"); |
| 154 | + $Logger->setRabbitmqPassword("guest"); |
| 155 | + $Logger->setLoggerTimeFormat("time.RFC3339"); |
| 156 | + $Logger->setQueuePrefix("ayopop"); |
| 157 | + $Logger->setQueueNames(array( |
| 158 | + "Api" => "api", |
| 159 | + "Debug" => "debug", |
| 160 | + "Info" => "info", |
| 161 | + "Warn" => "warning", |
| 162 | + "Error" => "error", |
| 163 | + "Critical" => "critical" |
| 164 | + )); |
| 165 | + |
| 166 | + $Logger->connect(); |
| 167 | + |
| 168 | + $Logger->publishMessage(); |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * @expectedException \TypeError |
| 173 | + */ |
| 174 | + |
| 175 | + public function testTypeInfo() |
| 176 | + { |
| 177 | + |
| 178 | + $Logger = Logging::getInstance(); |
| 179 | + $Logger->setRabbitmqHost("127.0.0.1"); |
| 180 | + $Logger->setRabbitmqPort("5672"); |
| 181 | + $Logger->setRabbitmqUser("guest"); |
| 182 | + $Logger->setRabbitmqPassword("guest"); |
| 183 | + $Logger->setLoggerTimeFormat("time.RFC3339"); |
| 184 | + $Logger->setQueuePrefix("ayopop"); |
| 185 | + $Logger->setQueueNames(array( |
| 186 | + "Api" => "api", |
| 187 | + "Debug" => "debug", |
| 188 | + "Info" => "info", |
| 189 | + "Warn" => "warning", |
| 190 | + "Error" => "error", |
| 191 | + "Critical" => "critical" |
| 192 | + )); |
| 193 | + |
| 194 | + $Logger->connect(); |
| 195 | + $Logger->info("saurav", "test"); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * @expectedException \ArgumentCountError |
| 200 | + */ |
| 201 | + |
| 202 | + public function testArgumentInfo() |
| 203 | + { |
| 204 | + |
| 205 | + $Logger = Logging::getInstance(); |
| 206 | + $Logger->setRabbitmqHost("127.0.0.1"); |
| 207 | + $Logger->setRabbitmqPort("5672"); |
| 208 | + $Logger->setRabbitmqUser("guest"); |
| 209 | + $Logger->setRabbitmqPassword("guest"); |
| 210 | + $Logger->setLoggerTimeFormat("time.RFC3339"); |
| 211 | + $Logger->setQueuePrefix("ayopop"); |
| 212 | + $Logger->setQueueNames(array( |
| 213 | + "Api" => "api", |
| 214 | + "Debug" => "debug", |
| 215 | + "Info" => "info", |
| 216 | + "Warn" => "warning", |
| 217 | + "Error" => "error", |
| 218 | + "Critical" => "critical" |
| 219 | + )); |
| 220 | + |
| 221 | + $Logger->connect(); |
| 222 | + $Logger->info(); |
| 223 | + } |
| 224 | +} |
0 commit comments