• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing: class 'SQLite3' not found

#1
Question 
I'm using CI 4.0 (latest).
I try testing using PHPUnit. installed offline, not using composer.

Using
Code:
ControllerTester
work for simple pages. But error (HTTP Exception) for page which requires logged in.

Using FeatureTestCase however, not work and says class 'SQLite3' not found. When I see trace result, it points to
PHP Code:
\system\Database\SQLite3\Connection.php:89'new \SQLite3($this->database)' 
.
This should be SQLite3 class from php extension because it has root namespace. Normal page using that class is working. Using PHPUnit on CI4.0 is not.

I just test using simple page using
PHP Code:
$db = new \SQLite3($path); 
is work.

How do i resolve this?
Reply

#2
i tend to work from a position thats not great but works; then try to improve it.

So your using sqlite great choice, so i am.

This is how I got mine working . I put a file called "Art" which IS an sqlite db but didn't bother with siffix like .db

I put it in public directory (bad i know)

then in .env i put these lines :

#database.default.hostname = localhost
database.default.database = "Art"
database.default.username = ""
database.default.password = ""

in app/Config/Database.php i also have :


public $filesPath = APPPATH . 'Database/';

/**
* Lets you choose which connection group to
* use if no other is specified.
*
* @var string
*/
public $defaultGroup = 'default';

/**
* The default database connection.
*
* @var array
*/
public $default = [
'DSN' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => 'Art',
'DBDriver' => 'SQLite3',



haven't had time to find out what makes it work yet.


im not using anything special in a model just this code at start:


<?php namespace App\Andy;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;


class BlogModel extends Model

{

protected $table = 'blog';
protected $primaryKey = 'Id';
protected $allowedFields = ['title','article','image','slug'];
protected $limit;
protected $offset;

but it works eg see :

https://www.benxmidia.com/blogs

it gets all entries out of a blog table
Reply

#3
I didn't use CI4's database Library, I don't need it for now.
I just use plain \SQLite3 which comes from PHP extension to minimize overhead calls. Even i'm not using PDO SQLite.

Unfortunately FeatureTestCase calls CIDatabaseTestCase which use CI4's Db driver.
Reply

#4
You may need to write use \SQLite3; above your class, to load the global class instead of bundled one.
Reply

#5
(03-19-2020, 01:18 PM)jreklund Wrote: You may need to write  use \SQLite3; above your class, to load the global class instead of bundled one.

Doesn't work.
Where do i place it? On controller class or controller test class?
It doesn't work after i try on each
Reply

#6
(03-19-2020, 09:23 PM)anthos1984 Wrote:
(03-19-2020, 01:18 PM)jreklund Wrote: You may need to write  use \SQLite3; above your class, to load the global class instead of bundled one.

Doesn't work.
Where do i place it? On controller class or controller test class?
It doesn't work after i try on each

You place it in the file you want to use it. I'm afraid I don't have any more tips than that, haven't used SQLite before.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.