2

My PHPUnit test is throwing an error saying that my file_managed test database table does not exist. What module do I need to include for that test table to get created? I would think it should be the file module, but I've already got that listed in my $modules array.

This is a Kernel test and I've been trying to fill up the modules array with everything I can think of that might actually get that table created.

  public static $modules = [
    'system',
    'path',
    'user',
    'file',
    'file_test',
    'node',
    'field',
    'media_entity',
    'entity',
    'image',
    'graphql',
    'graphql_core',
    'custom_graphql_file_upload',
    'custom_graphql_field'
  ];

Here's the error:

Invalid GraphQL query. Errors: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'contenta.test87607590file_managed' doesn't exist: INSERT INTO {file_managed} (uuid, langcode, uid, filename, uri, filemime, filesize, status, created, changed) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array

I'm trying to test a graphql file upload to make sure the file entity gets created as expected. I have a lot more tests I want to write and lot more that needs to be solved with multi-part/form data, etc, but I need to figure this out first I think.

Here's the full test https://github.com/justinlevi/graphql_custom_file_upload/blob/feature/PHPUnitTest_WIP/tests/src/Kernel/MutationFileUploadTest.php

All other code posted as well on the WIP branch.

4

Ugh... Forgot to install the entitySchema.

This is how to do it in the setup method

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this->installConfig('system');
    $this->installConfig('graphql');
    $this->installConfig('file');
    $this->installConfig('image');
    $this->installConfig('user');
    $this->installEntitySchema('user');
    $this->installEntitySchema('file');


    Role::load(RoleInterface::AUTHENTICATED_ID)
      ->grantPermission('execute graphql requests')
      ->grantPermission('create media')
      ->grantPermission('view media')
      ->grantPermission('access content')
      ->grantPermission('bypass node access')
      ->grantPermission('create url aliases')
      ->save();
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.