Best Atoum code snippet using namespace
FlashMessenger.php
Source:FlashMessenger.php
...5 * @link http://github.com/zendframework/zf2 for the canonical source repository6 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)7 * @license http://framework.zend.com/license/new-bsd New BSD License8 */9namespace Zend\Mvc\Controller\Plugin;10use ArrayIterator;11use Countable;12use IteratorAggregate;13use Zend\Session\Container;14use Zend\Session\ManagerInterface as Manager;15use Zend\Stdlib\SplQueue;16/**17 * Flash Messenger - implement session-based messages18 */19class FlashMessenger extends AbstractPlugin implements IteratorAggregate, Countable20{21 /**22 * Default messages namespace23 */24 const NAMESPACE_DEFAULT = 'default';25 /**26 * Success messages namespace27 */28 const NAMESPACE_SUCCESS = 'success';29 /**30 * Warning messages namespace31 */32 const NAMESPACE_WARNING = 'warning';33 /**34 * Error messages namespace35 */36 const NAMESPACE_ERROR = 'error';37 /**38 * Info messages namespace39 */40 const NAMESPACE_INFO = 'info';41 /**42 * @var Container43 */44 protected $container;45 /**46 * Messages from previous request47 * @var array48 */49 protected $messages = array();50 /**51 * @var Manager52 */53 protected $session;54 /**55 * Whether a message has been added during this request56 *57 * @var bool58 */59 protected $messageAdded = false;60 /**61 * Instance namespace, default is 'default'62 *63 * @var string64 */65 protected $namespace = self::NAMESPACE_DEFAULT;66 /**67 * Set the session manager68 *69 * @param Manager $manager70 * @return FlashMessenger71 */72 public function setSessionManager(Manager $manager)73 {74 $this->session = $manager;75 return $this;76 }77 /**78 * Retrieve the session manager79 *80 * If none composed, lazy-loads a SessionManager instance81 *82 * @return Manager83 */84 public function getSessionManager()85 {86 if (!$this->session instanceof Manager) {87 $this->setSessionManager(Container::getDefaultManager());88 }89 return $this->session;90 }91 /**92 * Get session container for flash messages93 *94 * @return Container95 */96 public function getContainer()97 {98 if ($this->container instanceof Container) {99 return $this->container;100 }101 $manager = $this->getSessionManager();102 $this->container = new Container('FlashMessenger', $manager);103 return $this->container;104 }105 /**106 * Change the namespace messages are added to107 *108 * Useful for per action controller messaging between requests109 *110 * @param string $namespace111 * @return FlashMessenger Provides a fluent interface112 */113 public function setNamespace($namespace = 'default')114 {115 $this->namespace = $namespace;116 return $this;117 }118 /**119 * Get the message namespace120 *121 * @return string122 */123 public function getNamespace()124 {125 return $this->namespace;126 }127 /**128 * Add a message129 *130 * @param string $message131 * @return FlashMessenger Provides a fluent interface132 */133 public function addMessage($message)134 {135 $container = $this->getContainer();136 $namespace = $this->getNamespace();137 if (!$this->messageAdded) {138 $this->getMessagesFromContainer();139 $container->setExpirationHops(1, null);140 }141 if (!isset($container->{$namespace})142 || !($container->{$namespace} instanceof SplQueue)143 ) {144 $container->{$namespace} = new SplQueue();145 }146 $container->{$namespace}->push($message);147 $this->messageAdded = true;148 return $this;149 }150 /**151 * Add a message with "info" type152 *153 * @param string $message154 * @return FlashMessenger155 */156 public function addInfoMessage($message)157 {158 $namespace = $this->getNamespace();159 $this->setNamespace(self::NAMESPACE_INFO);160 $this->addMessage($message);161 $this->setNamespace($namespace);162 return $this;163 }164 /**165 * Add a message with "success" type166 *167 * @param string $message168 * @return FlashMessenger169 */170 public function addSuccessMessage($message)171 {172 $namespace = $this->getNamespace();173 $this->setNamespace(self::NAMESPACE_SUCCESS);174 $this->addMessage($message);175 $this->setNamespace($namespace);176 return $this;177 }178 /**179 * Add a message with "warning" type180 *181 * @param string $message182 * @return FlashMessenger183 */184 public function addWarningMessage($message)185 {186 $namespace = $this->getNamespace();187 $this->setNamespace(self::NAMESPACE_WARNING);188 $this->addMessage($message);189 $this->setNamespace($namespace);190 return $this;191 }192 /**193 * Add a message with "error" type194 *195 * @param string $message196 * @return FlashMessenger197 */198 public function addErrorMessage($message)199 {200 $namespace = $this->getNamespace();201 $this->setNamespace(self::NAMESPACE_ERROR);202 $this->addMessage($message);203 $this->setNamespace($namespace);204 return $this;205 }206 /**207 * Whether a specific namespace has messages208 *209 * @return bool210 */211 public function hasMessages()212 {213 $this->getMessagesFromContainer();214 return isset($this->messages[$this->getNamespace()]);215 }216 /**217 * Whether "info" namespace has messages218 *219 * @return bool220 */221 public function hasInfoMessages()222 {223 $namespace = $this->getNamespace();224 $this->setNamespace(self::NAMESPACE_INFO);225 $hasMessages = $this->hasMessages();226 $this->setNamespace($namespace);227 return $hasMessages;228 }229 /**230 * Whether "success" namespace has messages231 *232 * @return bool233 */234 public function hasSuccessMessages()235 {236 $namespace = $this->getNamespace();237 $this->setNamespace(self::NAMESPACE_SUCCESS);238 $hasMessages = $this->hasMessages();239 $this->setNamespace($namespace);240 return $hasMessages;241 }242 /**243 * Whether "warning" namespace has messages244 *245 * @return bool246 */247 public function hasWarningMessages()248 {249 $namespace = $this->getNamespace();250 $this->setNamespace(self::NAMESPACE_WARNING);251 $hasMessages = $this->hasMessages();252 $this->setNamespace($namespace);253 return $hasMessages;254 }255 /**256 * Whether "error" namespace has messages257 *258 * @return bool259 */260 public function hasErrorMessages()261 {262 $namespace = $this->getNamespace();263 $this->setNamespace(self::NAMESPACE_ERROR);264 $hasMessages = $this->hasMessages();265 $this->setNamespace($namespace);266 return $hasMessages;267 }268 /**269 * Get messages from a specific namespace270 *271 * @return array272 */273 public function getMessages()274 {275 if ($this->hasMessages()) {276 return $this->messages[$this->getNamespace()]->toArray();277 }278 return array();279 }280 /**281 * Get messages from "info" namespace282 *283 * @return array284 */285 public function getInfoMessages()286 {287 $namespace = $this->getNamespace();288 $this->setNamespace(self::NAMESPACE_INFO);289 $messages = $this->getMessages();290 $this->setNamespace($namespace);291 return $messages;292 }293 /**294 * Get messages from "success" namespace295 *296 * @return array297 */298 public function getSuccessMessages()299 {300 $namespace = $this->getNamespace();301 $this->setNamespace(self::NAMESPACE_SUCCESS);302 $messages = $this->getMessages();303 $this->setNamespace($namespace);304 return $messages;305 }306 /**307 * Get messages from "warning" namespace308 *309 * @return array310 */311 public function getWarningMessages()312 {313 $namespace = $this->getNamespace();314 $this->setNamespace(self::NAMESPACE_WARNING);315 $messages = $this->getMessages();316 $this->setNamespace($namespace);317 return $messages;318 }319 /**320 * Get messages from "error" namespace321 *322 * @return array323 */324 public function getErrorMessages()325 {326 $namespace = $this->getNamespace();327 $this->setNamespace(self::NAMESPACE_ERROR);328 $messages = $this->getMessages();329 $this->setNamespace($namespace);330 return $messages;331 }332 /**333 * Clear all messages from the previous request & current namespace334 *335 * @return bool True if messages were cleared, false if none existed336 */337 public function clearMessages()338 {339 if ($this->hasMessages()) {340 unset($this->messages[$this->getNamespace()]);341 return true;342 }343 return false;344 }345 /**346 * Clear all messages from specific namespace347 *348 * @param string $namespaceToClear349 * @return bool True if messages were cleared, false if none existed350 */351 public function clearMessagesFromNamespace($namespaceToClear)352 {353 $namespace = $this->getNamespace();354 $this->setNamespace($namespaceToClear);355 $cleared = $this->clearMessages();356 $this->setNamespace($namespace);357 return $cleared;358 }359 /**360 * Clear all messages from the container361 *362 * @return bool True if messages were cleared, false if none existed363 */364 public function clearMessagesFromContainer()365 {366 $this->getMessagesFromContainer();367 if (empty($this->messages)) {368 return false;369 }370 unset($this->messages);371 $this->messages = array();372 return true;373 }374 /**375 * Check to see if messages have been added to the current376 * namespace within this request377 *378 * @return bool379 */380 public function hasCurrentMessages()381 {382 $container = $this->getContainer();383 $namespace = $this->getNamespace();384 return isset($container->{$namespace});385 }386 /**387 * Check to see if messages have been added to "info"388 * namespace within this request389 *390 * @return bool391 */392 public function hasCurrentInfoMessages()393 {394 $namespace = $this->getNamespace();395 $this->setNamespace(self::NAMESPACE_INFO);396 $hasMessages = $this->hasCurrentMessages();397 $this->setNamespace($namespace);398 return $hasMessages;399 }400 /**401 * Check to see if messages have been added to "success"402 * namespace within this request403 *404 * @return bool405 */406 public function hasCurrentSuccessMessages()407 {408 $namespace = $this->getNamespace();409 $this->setNamespace(self::NAMESPACE_SUCCESS);410 $hasMessages = $this->hasCurrentMessages();411 $this->setNamespace($namespace);412 return $hasMessages;413 }414 /**415 * Check to see if messages have been added to "warning"416 * namespace within this request417 *418 * @return bool419 */420 public function hasCurrentWarningMessages()421 {422 $namespace = $this->getNamespace();423 $this->setNamespace(self::NAMESPACE_WARNING);424 $hasMessages = $this->hasCurrentMessages();425 $this->setNamespace($namespace);426 return $hasMessages;427 }428 /**429 * Check to see if messages have been added to "error"430 * namespace within this request431 *432 * @return bool433 */434 public function hasCurrentErrorMessages()435 {436 $namespace = $this->getNamespace();437 $this->setNamespace(self::NAMESPACE_ERROR);438 $hasMessages = $this->hasCurrentMessages();439 $this->setNamespace($namespace);440 return $hasMessages;441 }442 /**443 * Get messages that have been added to the current444 * namespace within this request445 *446 * @return array447 */448 public function getCurrentMessages()449 {450 if ($this->hasCurrentMessages()) {451 $container = $this->getContainer();452 $namespace = $this->getNamespace();453 return $container->{$namespace}->toArray();454 }455 return array();456 }457 /**458 * Get messages that have been added to the "info"459 * namespace within this request460 *461 * @return array462 */463 public function getCurrentInfoMessages()464 {465 $namespace = $this->getNamespace();466 $this->setNamespace(self::NAMESPACE_INFO);467 $messages = $this->getCurrentMessages();468 $this->setNamespace($namespace);469 return $messages;470 }471 /**472 * Get messages that have been added to the "success"473 * namespace within this request474 *475 * @return array476 */477 public function getCurrentSuccessMessages()478 {479 $namespace = $this->getNamespace();480 $this->setNamespace(self::NAMESPACE_SUCCESS);481 $messages = $this->getCurrentMessages();482 $this->setNamespace($namespace);483 return $messages;484 }485 /**486 * Get messages that have been added to the "warning"487 * namespace within this request488 *489 * @return array490 */491 public function getCurrentWarningMessages()492 {493 $namespace = $this->getNamespace();494 $this->setNamespace(self::NAMESPACE_WARNING);495 $messages = $this->getCurrentMessages();496 $this->setNamespace($namespace);497 return $messages;498 }499 /**500 * Get messages that have been added to the "error"501 * namespace within this request502 *503 * @return array504 */505 public function getCurrentErrorMessages()506 {507 $namespace = $this->getNamespace();508 $this->setNamespace(self::NAMESPACE_ERROR);509 $messages = $this->getCurrentMessages();510 $this->setNamespace($namespace);511 return $messages;512 }513 /**514 * Get messages that have been added to the current515 * namespace in specific namespace516 *517 * @param string $namespaceToGet518 * @return array519 */520 public function getCurrentMessagesFromNamespace($namespaceToGet)521 {522 $namespace = $this->getNamespace();523 $this->setNamespace($namespaceToGet);524 $messages = $this->getCurrentMessages();525 $this->setNamespace($namespace);526 return $messages;527 }528 /**529 * Clear messages from the current request and current namespace530 *531 * @return bool True if current messages were cleared, false if none existed.532 */533 public function clearCurrentMessages()534 {535 if ($this->hasCurrentMessages()) {536 $container = $this->getContainer();537 $namespace = $this->getNamespace();538 unset($container->{$namespace});539 return true;540 }541 return false;542 }543 /**544 * Clear messages from the current namespace545 *546 * @param string $namespaceToClear547 * @return bool True if current messages were cleared from the given namespace, false if none existed.548 */549 public function clearCurrentMessagesFromNamespace($namespaceToClear)550 {551 $namespace = $this->getNamespace();552 $this->setNamespace($namespaceToClear);553 $cleared = $this->clearCurrentMessages();554 $this->setNamespace($namespace);555 return $cleared;556 }557 /**558 * Clear messages from the container559 *560 * @return bool True if current messages were cleared from the container, false if none existed.561 */562 public function clearCurrentMessagesFromContainer()563 {564 $container = $this->getContainer();565 $namespaces = array();566 foreach ($container as $namespace => $messages) {567 $namespaces[] = $namespace;568 }569 if (empty($namespaces)) {570 return false;571 }572 foreach ($namespaces as $namespace) {573 unset($container->{$namespace});574 }575 return true;576 }577 /**578 * Complete the IteratorAggregate interface, for iterating579 *580 * @return ArrayIterator581 */582 public function getIterator()583 {584 if ($this->hasMessages()) {585 return new ArrayIterator($this->getMessages());586 }587 return new ArrayIterator();588 }589 /**590 * Complete the countable interface591 *592 * @return int593 */594 public function count()595 {596 if ($this->hasMessages()) {597 return count($this->getMessages());598 }599 return 0;600 }601 /**602 * Get messages from a specific namespace603 *604 * @param string $namespaceToGet605 * @return array606 */607 public function getMessagesFromNamespace($namespaceToGet)608 {609 $namespace = $this->getNamespace();610 $this->setNamespace($namespaceToGet);611 $messages = $this->getMessages();612 $this->setNamespace($namespace);613 return $messages;614 }615 /**616 * Pull messages from the session container617 *618 * Iterates through the session container, removing messages into the local619 * scope.620 *621 * @return void622 */623 protected function getMessagesFromContainer()624 {625 if (!empty($this->messages) || $this->messageAdded) {626 return;627 }628 $container = $this->getContainer();629 $namespaces = array();630 foreach ($container as $namespace => $messages) {631 $this->messages[$namespace] = $messages;632 $namespaces[] = $namespace;633 }634 foreach ($namespaces as $namespace) {635 unset($container->{$namespace});636 }637 }638}...
namespace
Using AI Code Generation
1$test = new \Atoum\Test();2$test = new \Atoum\Test();3$test = new \Atoum\Test();4$test = new \Atoum\Test();5$test = new \Atoum\Test();6$test = new \Atoum\Test();7$test = new \Atoum\Test();8$test = new \Atoum\Test();9$test = new \Atoum\Test();10$test = new \Atoum\Test();11$test = new \Atoum\Test();12$test = new \Atoum\Test();13$test = new \Atoum\Test();14$test = new \Atoum\Test();15$test = new \Atoum\Test();16$test = new \Atoum\Test();17$test = new \Atoum\Test();
namespace
Using AI Code Generation
1use atoum\atoum;2use atoum\atoum\reports;3use atoum\atoum\reports\realtime;4use atoum\atoum\reports\realtime\cli;5use atoum\atoum\reports\realtime\cli\colorizer;6use atoum\atoum\reports\realtime\cli\colorizer\styles;7use atoum\atoum\reports\realtime\cli\colorizer\styles\foreground;8use atoum\atoum\reports\realtime\cli\colorizer\styles\background;9use atoum\atoum\reports\realtime\cli\colorizer\styles\text;10use atoum\atoum\reports\realtime\cli\colorizer\styles\text\bold;11use atoum\atoum\reports\realtime\cli\colorizer\styles\text\blink;12use atoum\atoum\reports\realtime\cli\colorizer\styles\text\conceal;13use atoum\atoum\reports\realtime\cli\colorizer\styles\text\crossedout;14use atoum\atoum\reports\realtime\cli\colorizer\styles\text\doubleunderlined;15use atoum\atoum\reports\realtime\cli\colorizer\styles\text\highlight;
namespace
Using AI Code Generation
1use Atoum\Atoum;2use Atoum\Atoum\Asserters;3use Atoum\Atoum\Asserters\Variable;4use Atoum\Atoum\Asserters\Variable\String;5use Atoum\Atoum;6use Atoum\Atoum\Asserters;7use Atoum\Atoum\Asserters\Variable;8use Atoum\Atoum\Asserters\Variable\String;9use Atoum\Atoum;10use Atoum\Atoum\Asserters;11use Atoum\Atoum\Asserters\Variable;12use Atoum\Atoum\Asserters\Variable\String;13use Atoum\Atoum;14use Atoum\Atoum\Asserters;15use Atoum\Atoum\Asserters\Variable;
namespace
Using AI Code Generation
1use atoum\atoum;2use atoum\atoum\runner;3use atoum\atoum\test;4use atoum\atoum\report;5use atoum\atoum\asserters;6use atoum\atoum\report\fields\runner\result\atoum;7use atoum\atoum\report\fields\runner\result\tests;8use atoum\atoum\report\fields\runner\result\failures;9use atoum\atoum\report\fields\runner\result\errors;10use atoum\atoum\report\fields\runner\result\exceptions;11use atoum\atoum\report\fields\runner\result\outputs;12use atoum\atoum\report\fields\runner\result\duration;13use atoum\atoum\report\fields\runner\result\memory;14use atoum\atoum\report\fields\runner\result\coverage;15use atoum\atoum\report\fields\runner\tests\coverage;16use atoum\atoum\report\fields\runner\tests\uncompleted;17use atoum\atoum\report\fields\runner\tests\void;18use atoum\atoum\report\fields\runner\tests\skipped;
namespace
Using AI Code Generation
1use atoum\atoum;2use atoum\atoum\report\fields\runner\result\logo;3use atoum\atoum\reports\realtime;4use atoum\atoum\reports\realtime\cli;5use atoum\atoum\reports\realtime\cli\progressBar;6use atoum\atoum\reports\realtime\cli\progressBar\cli;7use atoum\atoum\reports\realtime\cli\progressBar\cli\colorizer;8use atoum\atoum\reports\realtime\cli\progressBar\cli\colorizer\styles;9use atoum\atoum\reports\realtime\cli\progressBar\cli\colorizer\styles\foreground;10use atoum\atoum\reports\realtime\cli\progressBar\cli\colorizer\styles\foreground\green;11use atoum\atoum\reports\realtime\cli\progressBar\cli\colorizer\styles\foreground\red;12use atoum\atoum\reports\realtime\cli\progressBar\cli\colorizer\styles\foreground\yellow;13use atoum\atoum\reports\realtime\cli\progressBar\cli\output;14use atoum\atoum\reports\realtime\cli\progressBar\cli\output\stderr;15use atoum\atoum\reports\realtime\cli\progressBar\cli\output\stdout;
namespace
Using AI Code Generation
1use Atoum\Atoum;2$atoum = new Atoum();3$atoum->sayHello();4use Atoum\Atoum;5$atoum = new Atoum();6$atoum->sayHello();
namespace
Using AI Code Generation
1$atoum = new \atoum\atoum();2$atoum->setReport(\atoum\reports\realtime\cli::class);3$atoum->run();4$atoum = new \atoum\atoum();5$atoum->setReport(\atoum\reports\realtime\html::class);6$atoum->run();7$atoum = new \atoum\atoum();8$atoum->setReport(\atoum\reports\realtime\json::class);9$atoum->run();10$atoum = new \atoum\atoum();11$atoum->setReport(\atoum\reports\realtime\xunit::class);12$atoum->run();13$atoum = new \atoum\atoum();14$atoum->setReport(\atoum\reports\realtime\yml::class);15$atoum->run();16$atoum = new \atoum\atoum();17$atoum->setReport(\atoum\reports\realtime\markdown::class);18$atoum->run();19$atoum = new \atoum\atoum();20$atoum->setReport(\atoum\reports\realtime\cobertura::class);21$atoum->run();22$atoum = new \atoum\atoum();23$atoum->setReport(\atoum\reports\realtime\clover::class);24$atoum->run();
namespace
Using AI Code Generation
1namespace Atoum\Test;2class Foo {3 public function bar() {4 return 'bar';5 }6}7namespace Atoum\Test;8class Foo {9 public function bar() {10 return 'bar';11 }12}13namespace Atoum\Test;14class Foo {15 public function bar() {16 return 'bar';17 }18}19namespace Atoum\Test;20class Foo {21 public function bar() {22 return 'bar';23 }24}25namespace Atoum\Test;26class Foo {27 public function bar() {28 return 'bar';29 }30}31namespace Atoum\Test;32class Foo {33 public function bar() {34 return 'bar';35 }36}37namespace Atoum\Test;38class Foo {39 public function bar() {40 return 'bar';41 }42}43namespace Atoum\Test;44class Foo {45 public function bar() {46 return 'bar';47 }48}49namespace Atoum\Test;50class Foo {51 public function bar() {52 return 'bar';53 }54}55namespace Atoum\Test;56class Foo {57 public function bar() {58 return 'bar';59 }60}61namespace Atoum\Test;62class Foo {63 public function bar() {64 return 'bar';65 }66}67namespace Atoum\Test;68class Foo {69 public function bar() {70 return 'bar';71 }72}73namespace Atoum\Test;74class Foo {75 public function bar() {76 return 'bar';77 }78}79namespace Atoum\Test;80class Foo {81 public function bar() {82 return 'bar';83 }84}85namespace Atoum\Test;86class Foo {87 public function bar() {88 return 'bar';89 }90}91namespace Atoum\Test;92class Foo {93 public function bar() {94 return 'bar';95 }96}97namespace Atoum\Test;98class Foo {99 public function bar() {
namespace
Using AI Code Generation
1namespace Atoum;2require_once 'vendor/autoload.php';3use mageekguy\atoum;4{5 public function testSomething()6 {7 ->if($foo = new \foo())8 ->and($foo->bar())9 ->mock($foo)10 ->call('bar')11 ->once()12 ;13 }14}15namespace Atoum;16require_once 'vendor/autoload.php';17use mageekguy\atoum;18{19 public function testSomething()20 {21 ->if($foo = new \foo())22 ->and($foo->bar())23 ->mock($foo)24 ->call('bar')25 ->once()26 ;27 }28}29namespace Atoum;30require_once 'vendor/autoload.php';31use mageekguy\atoum;32{33 public function testSomething()34 {35 ->if($foo = new \foo())36 ->and($foo->bar())37 ->mock($foo)38 ->call('bar')39 ->once()40 ;41 }42}43namespace Atoum;44require_once 'vendor/autoload.php';45use mageekguy\atoum;46{47 public function testSomething()48 {49 ->if($foo = new \foo())50 ->and($foo->bar())51 ->mock($foo)52 ->call('bar')53 ->once()54 ;55 }56}57namespace Atoum;58require_once 'vendor/autoload.php';59use mageekguy\atoum;60{61 public function testSomething()62 {63 ->if($foo = new \foo())64 ->and($foo->bar())65 ->mock($foo)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!