1

I'm with problem with tests in Laravel. I don't know why the users table isn't be created, because all other tables are ok.

The database for tests is Sqlite running in :memory:

My PHP Unit configuration file (phpunit.xml)

      <php>
              <env name="APP_ENV" value="testing"/>
              <env name="DB_CONNECTION" value="sqlite"/>
              <env name="DB_DATABASE" value=":memory:"/>
              <env name="CACHE_DRIVER" value="array"/>
              <env name="SESSION_DRIVER" value="array"/>
              <env name="QUEUE_DRIVER" value="sync"/>
          </php>

Users Migration ( create_users_table )

      use Illuminate\Support\Facades\Schema;
      use Illuminate\Database\Schema\Blueprint;
      use Illuminate\Database\Migrations\Migration;

      class CreateUsersTable extends Migration
      {
          /**
           * Run the migrations.
           *
           * @return void
           */
          public function up()
          {
              Schema::create('user', function (Blueprint $table) {

                  $table->increments('id');
                  $table->integer('status')->nullable()->default(1);
                  $table->string('name');
                  $table->string('email')->unique();
                  $table->string('password');
                  $table->string('sysid', 20)->nullable();
                  $table->string('avatar')->nullable();
                  $table->string('cpf', 18)->nullable();

                  $table->rememberToken();
                  $table->timestamps();
              });
          }

          /**
           * Reverse the migrations.
           *
           * @return void
           */
          public function down()
          {
              Schema::dropIfExists('user');
          }
      }

tests/Unit/RoleTest.php

    <?php

    namespace Tests\Unit;

    use Tests\TestCase;
    use Illuminate\Foundation\Testing\DatabaseMigrations;
    use Illuminate\Foundation\Testing\DatabaseTransactions;

    class RoleTest extends TestCase
    {

        use DatabaseMigrations;

        protected $role;
        protected $permission;


        public function setUp() {

            parent::setUp();
            $this->role = factory('App\Model\ACL\Role')->create();
            $this->permission = factory('App\Model\ACL\Permission')->create();
        }


        /** @test */
        public function a_role_has_permissions ()
        {

            $this->assertInstanceOf(
        'Illuminate\Database\Eloquent\Collection', $this->role->permissions
            );
        }

        /** @test */
        public function a_role_gives_permission_to ()
        {
            $permission = $this->role->givePermissionTo($this->permission);
            $this->assertInstanceOf('App\Model\ACL\Permission', $permission);

        }


        /** @test */
        public function a_role_has_permission ()
        {
            $permission = $this->role->givePermissionTo($this->permission);
            $this->assertTrue($this->role->hasPermission($this->permission));
        }


        /** @test */
        public function a_role_has_many_users ()
        {

            $this->assertInstanceOf(
                'Illuminate\Database\Eloquent\Collection', $this->role->users
            );

        }
    }

The tests are given the following errors:

    1) Tests\Unit\RoleTest::a_role_has_many_users
    Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: users (SQL: select "users".*, "role_user"."role_id" as "pivot_role_id", "role_user"."user_id" as "pivot_user_id" from "users" inner join "role_user" on "users"."id" = "role_user"."user_id" where "role_user"."role_id" = 1)


    Caused by
    PDOException: SQLSTATE[HY000]: General error: 1 no such table: users

1 Answer 1

1

For some reason that I don't know why, I miss the 's' in Migration, create_users_table..

But how I lost the 's' in code :O Lol!!!!

Was a dummy mistake

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.