# CakePHP 3.8 - Error PHPUnit with DataProvider & Custom Authenticate

**URL:** https://discourse.cakephp.org/t/cakephp-3-8-error-phpunit-with-dataprovider-custom-authenticate/7482
**Category:** Need Help
**Created:** [March 16, 2020, 6:17pm UTC](https://discourse.cakephp.org/t/cakephp-3-8-error-phpunit-with-dataprovider-custom-authenticate/7482 "2020-03-16T18:17:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LucasGoncalves](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@LucasGoncalves](https://discourse.cakephp.org/u/LucasGoncalves)
#### Post date: [March 16, 2020, 6:17pm UTC](https://discourse.cakephp.org/t/cakephp-3-8-error-phpunit-with-dataprovider-custom-authenticate/7482/1 "2020-03-16T18:17:36Z")

</div>

I need help with CakePHP 3.8 unit testing.

I have create a [Custom Autheticate](https://book.cakephp.org/3/en/controllers/components/authentication.html) in CakePHP:

```
<?php
namespace Cake\Auth;

use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Network\Response;

class BasicFixedAuthenticate extends BasicAuthenticate

{

    public function authenticate(Request $request, Response $response)

    {

        return $this->getUser($request);

    }

    public function getUser(Request $request)

    {

        $username = env('PHP_AUTH_USER');

        $pass = env('PHP_AUTH_PW');

        if ((empty($username) || $username === '') || (empty($pass) || $pass === '')) {

            return false;

        }

    

    if ($username == $this->_config['fields']['username'] && $pass == $this->_config['fields']['password']) {

        return ['User' => $username, 'Password' => $pass];

    }

    return false;

}

```

}

I use this on my **Initialize()** on my application:

```
    public function initialize()
        {
            $this->loadComponent('Auth', [
                'authenticate' => [
                    'BasicFixed' => [
                        'fields' => ['username' => env('bot_user'), 'password' => env('bot_pass')],
                        'userModel' => 'Users'
                    ],
                ],
                'storage' => 'Memory',
                'unauthorizedRedirect' => false
            ]); 
            
        }

```

So, everthing work fine! but in PHPUnit a have a problem using ProviderData:

On my testing, the first time of testing running (XPTO\_1), works perfect, using ProviderData.

Example:

```
    public function WebhookProvider()
    {
        return [
            'XPTO_1' => [['action' => 'XPTO', 'placa' => 'ABC1234']],
            'XPTO_2' => [['action' => 'XPTO', 'placa' => 'ABC5555']],
     
        ];
    }
/**
 * @dataProvider WebhookProvider
 */
public function testWebhook($data)
{
    
    $_SERVER['PHP_AUTH_USER'] = 'bot_chat';
    $_SERVER['PHP_AUTH_PW'] = 'password';

    $this->post('bot_soe/webhook', $data);
    $response = $this->_response->body();
}

```

but on second test (XPTO\_2) i got the error:

Fatal error: Cannot declare class Cake\Auth\BasicFixedAuthenticate, because the name is already in use in /home/sistemas/BtecApiCore/src/Auth/BasicFixedAuthenticate.php on line 32

Someone can help me with this problem?

---

<div class="post-metadata">

### Author: ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)
#### Post date: [March 16, 2020, 6:36pm UTC](https://discourse.cakephp.org/t/cakephp-3-8-error-phpunit-with-dataprovider-custom-authenticate/7482/2 "2020-03-16T18:36:29Z")

</div>

Your `BasicFixedAuthenticate` class is in the `Cake\Auth` namespace; it should presumably be in `App\Auth`.

---

<div class="post-metadata">

### Author: ![LucasGoncalves](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@LucasGoncalves](https://discourse.cakephp.org/u/LucasGoncalves)
#### Post date: [March 16, 2020, 7:35pm UTC](https://discourse.cakephp.org/t/cakephp-3-8-error-phpunit-with-dataprovider-custom-authenticate/7482/3 "2020-03-16T19:35:42Z")

</div>

Zuluru, thanks for help!

i have change the code like this:

```
<?php

namespace App\Auth;

use Cake\Network\Exception\UnauthorizedException;

use Cake\Network\Request;

use Cake\Network\Response;

use Cake\Auth\BasicAuthenticate;

class BasicFixedAuthenticate extends BasicAuthenticate

{
[...]
}

```

Now, the unit testing work fine with DataProvider.
