Abdelrahman Shahin
Abdelrahman Shahin

Reputation: 126

i'm doing test in laravel whene run command php artisan test see this error

PS C:\xampp\htdocs\laravel_testing> PHP artisan test Warning: TTY mode is not supported on the Windows platform.

RUNS Tests\Unit\AccountantHelperTest • it can find profit

Tests: 3 pending

FAIL Tests\Unit\AccountantHelperTest ✕ it can find profit

Tests: 1 failed, 2 pending

Error

Class 'App\AccountantHelper' not found

at C:\xampp\htdocs\laravel_testing\tests\Unit\AccountantHelperTest.php:16 12| * @test 13| */ 14| public function it_can_find_profit() 15| {

16| $profit= AccountantHelper::findProfit(100); 17| $this->assertEquals(10,$profit); 18| 19| } 20| }

1 C:\xampp\htdocs\laravel_testing\vendor\phpunit\phpunit\src\Framework\TestCase.php:1472 Tests\Unit\AccountantHelperTest::it_can_find_profit()

2 C:\xampp\htdocs\laravel_testing\vendor\phpunit\phpunit\src\Framework\TestCase.php:1092 PHPUnit\Framework\TestCase::runTest()

AccountantHelper is a class in the folder app

<?php
namespace App;


class AccountantHelper
{

function Profit($amount)
{

    $profitPercent =10;
    return $profitPercent * $amount / 100 ;
}

}

AccountantHelperTest is file in tests/unit

<?php

namespace Tests\Unit;
use App\AccountantHelper;
use PHPUnit\Framework\TestCase;

class AccountantHelperTest extends TestCase
{
    /** @test  */
  function it_can_find_profit()
  {
          $Profit= AccountantHelper::Profit(100);
          $this->assertEquals(10,$Profit);

  }
}

Upvotes: 0

Views: 1151

Answers (1)

Mahbod Ahmadi
Mahbod Ahmadi

Reputation: 129

Your Profit method in AccountantHelper class is not static. Your code should be like this:

class AccountantHelper
{
    public static function Profit($amount)
    {
        $profitPercent =10;
        return $profitPercent * $amount / 100 ;
    }
}

Also, if that was an Eloquent Model and you had many queries on there you could use scope

Upvotes: 1

Related Questions