[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/tests/ProxyManagerTest/Signature/ -> SignatureCheckerTest.php (source)

   1  <?php
   2  /*
   3   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   4   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   5   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   6   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   7   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   8   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   9   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14   *
  15   * This software consists of voluntary contributions made by many individuals
  16   * and is licensed under the MIT license.
  17   */
  18  
  19  namespace ProxyManagerTest\Signature;
  20  
  21  use PHPUnit_Framework_TestCase;
  22  use ProxyManager\Signature\SignatureChecker;
  23  use ReflectionClass;
  24  
  25  /**
  26   * Tests for {@see \ProxyManager\Signature\SignatureChecker}
  27   *
  28   * @author Marco Pivetta <ocramius@gmail.com>
  29   * @license MIT
  30   *
  31   * @covers \ProxyManager\Signature\SignatureChecker
  32   * @group Coverage
  33   */
  34  class SignatureCheckerTest extends PHPUnit_Framework_TestCase
  35  {
  36      /**
  37       * @var string
  38       */
  39      protected $signatureExample = 'valid-signature';
  40  
  41      /**
  42       * @var SignatureChecker
  43       */
  44      private $signatureChecker;
  45  
  46      /**
  47       * @var \ProxyManager\Signature\SignatureGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
  48       */
  49      private $signatureGenerator;
  50  
  51      /**
  52       * {@inheritDoc}
  53       */
  54      protected function setUp()
  55      {
  56          $this->signatureGenerator = $this->getMock('ProxyManager\Signature\SignatureGeneratorInterface');
  57          $this->signatureChecker   = new SignatureChecker($this->signatureGenerator);
  58      }
  59  
  60      public function testCheckSignatureWithValidKey()
  61      {
  62          $this
  63              ->signatureGenerator
  64              ->expects($this->atLeastOnce())
  65              ->method('generateSignatureKey')
  66              ->with(array('foo' => 'bar'))
  67              ->will($this->returnValue('Example'));
  68          $this
  69              ->signatureGenerator
  70              ->expects($this->atLeastOnce())
  71              ->method('generateSignature')
  72              ->with(array('foo' => 'bar'))
  73              ->will($this->returnValue('valid-signature'));
  74  
  75          $this->signatureChecker->checkSignature(new ReflectionClass($this), array('foo' => 'bar'));
  76      }
  77  
  78      public function testCheckSignatureWithInvalidKey()
  79      {
  80          $this
  81              ->signatureGenerator
  82              ->expects($this->any())
  83              ->method('generateSignatureKey')
  84              ->with(array('foo' => 'bar'))
  85              ->will($this->returnValue('InvalidKey'));
  86          $this
  87              ->signatureGenerator
  88              ->expects($this->any())
  89              ->method('generateSignature')
  90              ->with(array('foo' => 'bar'))
  91              ->will($this->returnValue('valid-signature'));
  92  
  93          $this->setExpectedException('ProxyManager\Signature\Exception\MissingSignatureException');
  94  
  95          $this->signatureChecker->checkSignature(new ReflectionClass($this), array('foo' => 'bar'));
  96      }
  97  
  98      public function testCheckSignatureWithInvalidValue()
  99      {
 100          $this
 101              ->signatureGenerator
 102              ->expects($this->any())
 103              ->method('generateSignatureKey')
 104              ->with(array('foo' => 'bar'))
 105              ->will($this->returnValue('Example'));
 106          $this
 107              ->signatureGenerator
 108              ->expects($this->any())
 109              ->method('generateSignature')
 110              ->with(array('foo' => 'bar'))
 111              ->will($this->returnValue('invalid-signature'));
 112  
 113          $this->setExpectedException('ProxyManager\Signature\Exception\InvalidSignatureException');
 114  
 115          $this->signatureChecker->checkSignature(new ReflectionClass($this), array('foo' => 'bar'));
 116      }
 117  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1