1

I want to get the data from the below file. I want to know is this possible to achieve? and how we to import it in another file? Purpose of this, is for my unit testing.

I tried the below code but it returns an error.

dd(userData);

ErrorException: Use of undefined constant userData - assumed 'userData'


userData.php

<?php

return [
    [
        'name' => 'Perla',
        'age' => 13,
    ],
    [
        'name' => 'Felepe',
        'age' => 23,
    ],
    [
        'name' => 'Timoteo',
        'age' => 50,
    ]
]
  • you can put the file in the config folder and call it with `config('userData')` – N69S Sep 30 '21 at 10:33
  • @N69S i want to put it under the `tests` folder, since it will be use for testing. – アリ・ナディム Sep 30 '21 at 10:34
  • then what prevents you from adding that array into a method of the setup class like `getSampleUsers()` or something like that, why does it have to be in a seperate file ? – N69S Sep 30 '21 at 10:36
  • @N69S i think its messy. and thought to separate so, other test file can use it, just in case – アリ・ナディム Sep 30 '21 at 10:37
  • yeah, put it in the setup class, wich is accessible by all tests. – N69S Sep 30 '21 at 10:39
  • Does this answer your question? [What does the PHP error message "Notice: Use of undefined constant" mean?](https://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean) – ManojKiran A Sep 30 '21 at 12:56

1 Answers1

1

You can import it by following according to your userData.php

$userData = include('test/data/userData.php');
Hakan SONMEZ
  • 2,176
  • 2
  • 21
  • 32