public function testWithObjects() { $criteria = Criteria::create(TestUser::dao())->add(Expression::containsIp(IpRange::create('192.168.1.1-192.168.1.255'), 'ip'))->addProjection(Projection::property('id')); $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_user"."id" FROM "test_user" WHERE "test_user"."ip" <<= \'192.168.1.1-192.168.1.255\''); $criteria = Criteria::create(TestInternetProvider::dao())->add(Expression::containsIp('range', IpAddress::create('42.42.42.42')))->addProjection(Projection::property('id')); $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_internet_provider"."id" FROM "test_internet_provider" WHERE \'42.42.42.42\' <<= "test_internet_provider"."range"'); }
public function testIpRangeProperty() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $akado = TestInternetProvider::create()->setName('Akada')->setRange(IpRange::create(IpAddress::create('192.168.1.1'), IpAddress::create('192.168.1.42'))); TestInternetProvider::dao()->add($akado); $plainRange = Criteria::create(TestInternetProvider::dao())->addProjection(Projection::property('range'))->add(Expression::eq('name', 'Akada'))->getCustom(); $this->assertEquals($plainRange['range'], '192.168.1.1-192.168.1.42'); TestInternetProvider::dao()->add(TestInternetProvider::create()->setName('DomRu')->setRange(IpRange::create('192.168.2.0/24'))); $list = Criteria::create(TestInternetProvider::dao())->addOrder('id')->getList(); $this->assertEquals(count($list), 2); } }
public function testCreation() { $range = IpRange::create('192.168.2.1-192.168.255.255'); $anotherRange = IpRange::create(IpAddress::create('192.168.2.1'), IpAddress::create('192.168.255.255')); $this->assertEquals($range->toString(), $anotherRange->toString()); try { $range = IpRange::create('192.168.2.1-192.168.255.666'); $this->fail(); } catch (WrongArgumentException $e) { /**/ } try { $range = IpRange::create('192.168.666.1-192.168.255.254'); $this->fail(); } catch (WrongArgumentException $e) { /**/ } try { $range = IpRange::create(array(array(array(false)))); $this->fail(); } catch (WrongArgumentException $e) { /**/ } $slashRange = IpRange::create('192.168.1.0/30'); $this->assertEquals('192.168.1.0', $slashRange->getStart()->toString()); $this->assertEquals('192.168.1.3', $slashRange->getEnd()->toString()); try { $range = IpRange::create('192.168.1.0/4'); $this->fail(); } catch (WrongArgumentException $e) { /**/ } $range = IpRange::create('8.8/16'); $this->assertEquals($range->toString(), '8.8.0.0-8.8.255.255'); $range = IpRange::create('192.168.1.1'); $this->assertEquals($range->getStart()->toString(), $range->getEnd()->toString()); }