mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 20:20:15 +02:00
some explanations
This commit is contained in:
@@ -5,7 +5,7 @@ namespace DesignPatterns\Observer;
|
||||
/**
|
||||
* Observer pattern : The observed object (the subject)
|
||||
*
|
||||
* The subject maintains a list of Observer and send notificiations.
|
||||
* The subject maintains a list of Observers and sends notifications.
|
||||
*
|
||||
*/
|
||||
class User implements \SplSubject
|
||||
|
@@ -18,6 +18,12 @@ namespace DesignPatterns\Observer;
|
||||
class UserObserver implements \SplObserver
|
||||
{
|
||||
|
||||
/**
|
||||
* This is the only method to implement as an observer.
|
||||
* It is called by the Subject (usually by SplSubject::notify() )
|
||||
*
|
||||
* @param \SplSubject $subject
|
||||
*/
|
||||
public function update(\SplSubject $subject)
|
||||
{
|
||||
echo get_class($subject) . ' has been updated';
|
||||
|
@@ -18,6 +18,9 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
|
||||
$this->observer = new UserObserver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the notification
|
||||
*/
|
||||
public function testNotify()
|
||||
{
|
||||
$this->expectOutputString('DesignPatterns\Observer\User has been updated');
|
||||
@@ -27,6 +30,9 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
|
||||
$subject->property = 123;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the subscribing
|
||||
*/
|
||||
public function testAttachDetach()
|
||||
{
|
||||
$subject = new User();
|
||||
@@ -37,6 +43,9 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertAttributeEmpty('_observers', $subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the update() invocation on a mockup
|
||||
*/
|
||||
public function testUpdateCalling()
|
||||
{
|
||||
$subject = new User();
|
||||
|
Reference in New Issue
Block a user