<NME> WhitelistEntryUnitTest.php
<BEF> <?php

/*
 * This file is part of the Force Login module for Magento2.
 *
 * (c) bitExpert AG
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace BitExpert\ForceCustomerLogin\Test\Unit\Validator;

use BitExpert\ForceCustomerLogin\Validator\WhitelistEntry;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
 * Class WhitelistEntryUnitTest
 *
 * @package BitExpert\ForceCustomerLogin\Test\Unit\Validator
 */
class WhitelistEntryUnitTest extends TestCase
{
    /**
     * @test
     */
    public function validationFailsDueToLabelTooShort()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Label value is too short.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('');

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationFailsDueToLabelTooLong()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Label value is too long.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn(str_repeat('.', 256));

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationFailsDueToUrlRuleTooShort()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Url Rule value is too short.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('foo');
        $entity->expects($this->at(1))
            ->method('getUrlRule')
            ->willReturn('');

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationFailsDueToUrlRuleTooLong()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Url Rule value is too long.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('foo');
        $entity->expects($this->at(1))
            ->method('getUrlRule')
            ->willReturn(str_repeat('.', 256));

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationFailsDueToStrategyTooShort()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Strategy value is too short.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('foo');
        $entity->expects($this->at(1))
            ->method('getUrlRule')
            ->willReturn('foo');
        $entity->expects($this->at(2))
            ->method('getStrategy')
            ->willReturn('');

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationFailsDueToStrategyTooLong()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Strategy value is too long.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('foo');
        $entity->expects($this->at(1))
            ->method('getUrlRule')
            ->willReturn('foo');
        $entity->expects($this->at(2))
            ->method('getStrategy')
            ->willReturn(str_repeat('.', 256));

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationFailsDueToEditableFalseType()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Editable is no boolean value.');

        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('foo');
        $entity->expects($this->at(1))
            ->method('getUrlRule')
            ->willReturn('foo');
        $entity->expects($this->at(2))
            ->method('getStrategy')
            ->willReturn('foo');
        $entity->expects($this->at(3))
            ->method('getEditable')
            ->willReturn('foo');

        $validator = new WhitelistEntry();
        $validator->validate($entity);
    }

    /**
     * @test
     */
    public function validationSucceeds()
    {
        $entity = $this->getWhitelistEntry();
        $entity->expects($this->at(0))
            ->method('getLabel')
            ->willReturn('foo');
        $entity->expects($this->at(1))
            ->method('getUrlRule')
            ->willReturn('foo');
        $entity->expects($this->at(2))
            ->method('getStrategy')
            ->willReturn('foo');
        $entity->expects($this->at(3))
            ->method('getEditable')
            ->willReturn(false);

        $validator = new WhitelistEntry();
        $this->assertTrue($validator->validate($entity));
    }

    /**
     * @return MockObject|\BitExpert\ForceCustomerLogin\Model\WhitelistEntry
     */
    private function getWhitelistEntry()
    {
        return $this->getMockBuilder(\BitExpert\ForceCustomerLogin\Model\WhitelistEntry::class)
            ->disableOriginalConstructor()
            ->getMock();
    }
}

<MSG> Fix PHPUnit warnings

<DFF> @@ -31,7 +31,7 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Label value is too short.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('');
 
@@ -48,7 +48,7 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Label value is too long.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn(str_repeat('.', 256));
 
@@ -65,10 +65,10 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Url Rule value is too short.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('foo');
-        $entity->expects($this->at(1))
+        $entity->expects($this->any())
             ->method('getUrlRule')
             ->willReturn('');
 
@@ -85,10 +85,10 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Url Rule value is too long.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('foo');
-        $entity->expects($this->at(1))
+        $entity->expects($this->any())
             ->method('getUrlRule')
             ->willReturn(str_repeat('.', 256));
 
@@ -105,13 +105,13 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Strategy value is too short.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('foo');
-        $entity->expects($this->at(1))
+        $entity->expects($this->any())
             ->method('getUrlRule')
             ->willReturn('foo');
-        $entity->expects($this->at(2))
+        $entity->expects($this->any())
             ->method('getStrategy')
             ->willReturn('');
 
@@ -128,13 +128,13 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Strategy value is too long.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('foo');
-        $entity->expects($this->at(1))
+        $entity->expects($this->any())
             ->method('getUrlRule')
             ->willReturn('foo');
-        $entity->expects($this->at(2))
+        $entity->expects($this->any())
             ->method('getStrategy')
             ->willReturn(str_repeat('.', 256));
 
@@ -151,16 +151,16 @@ class WhitelistEntryUnitTest extends TestCase
         $this->expectExceptionMessage('Editable is no boolean value.');
 
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('foo');
-        $entity->expects($this->at(1))
+        $entity->expects($this->any())
             ->method('getUrlRule')
             ->willReturn('foo');
-        $entity->expects($this->at(2))
+        $entity->expects($this->any())
             ->method('getStrategy')
             ->willReturn('foo');
-        $entity->expects($this->at(3))
+        $entity->expects($this->any())
             ->method('getEditable')
             ->willReturn('foo');
 
@@ -174,16 +174,16 @@ class WhitelistEntryUnitTest extends TestCase
     public function validationSucceeds()
     {
         $entity = $this->getWhitelistEntry();
-        $entity->expects($this->at(0))
+        $entity->expects($this->any())
             ->method('getLabel')
             ->willReturn('foo');
-        $entity->expects($this->at(1))
+        $entity->expects($this->any())
             ->method('getUrlRule')
             ->willReturn('foo');
-        $entity->expects($this->at(2))
+        $entity->expects($this->any())
             ->method('getStrategy')
             ->willReturn('foo');
-        $entity->expects($this->at(3))
+        $entity->expects($this->any())
             ->method('getEditable')
             ->willReturn(false);
 

Fix PHPUnit warnings