|
| 1 | +<?php namespace Tests\unit; |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2025 OpenStack Foundation |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + **/ |
| 15 | + |
| 16 | +use LaravelDoctrine\ORM\Facades\EntityManager; |
| 17 | +use Models\BannedIP; |
| 18 | +use Tests\BrowserKitTestCase; |
| 19 | + |
| 20 | +/** |
| 21 | + * Class BannedIPMappingTest |
| 22 | + * @package Tests\unit |
| 23 | + */ |
| 24 | +class BannedIPMappingTest extends BrowserKitTestCase |
| 25 | +{ |
| 26 | + public function testBannedIPPersistence() |
| 27 | + { |
| 28 | + $ip = "127.0.0.1"; |
| 29 | + $banned_ip = new BannedIP(); |
| 30 | + $banned_ip->setIp("127.0.0.1"); |
| 31 | + $banned_ip->setExceptionType("TestExceptionType");; |
| 32 | + $banned_ip->setHits(1); |
| 33 | + |
| 34 | + EntityManager::persist($banned_ip); |
| 35 | + EntityManager::flush(); |
| 36 | + EntityManager::clear(); |
| 37 | + |
| 38 | + $repo = EntityManager::getRepository(BannedIP::class); |
| 39 | + $found_banned_ip = $repo->find($banned_ip->getId()); |
| 40 | + |
| 41 | + $this->assertInstanceOf(BannedIP::class, $found_banned_ip); |
| 42 | + $this->assertEquals($ip, $found_banned_ip->getIp()); |
| 43 | + } |
| 44 | +} |
0 commit comments